@@ -2236,7 +2236,17 @@ static int parse_control_option(const struct option *opt,
22362236{
22372237 struct record_opts * opts = opt -> value ;
22382238
2239- return evlist__parse_control (str , & opts -> ctl_fd , & opts -> ctl_fd_ack );
2239+ return evlist__parse_control (str , & opts -> ctl_fd , & opts -> ctl_fd_ack , & opts -> ctl_fd_close );
2240+ }
2241+
2242+ static void close_control_option (struct record_opts * opts )
2243+ {
2244+ if (opts -> ctl_fd_close ) {
2245+ opts -> ctl_fd_close = false;
2246+ close (opts -> ctl_fd );
2247+ if (opts -> ctl_fd_ack >= 0 )
2248+ close (opts -> ctl_fd_ack );
2249+ }
22402250}
22412251
22422252static void switch_output_size_warn (struct record * rec )
@@ -2578,9 +2588,10 @@ static struct option __record_options[] = {
25782588 "libpfm4 event selector. use 'perf list' to list available events" ,
25792589 parse_libpfm_events_option ),
25802590#endif
2581- OPT_CALLBACK (0 , "control" , & record .opts , "fd:ctl-fd[,ack-fd]" ,
2591+ OPT_CALLBACK (0 , "control" , & record .opts , "fd:ctl-fd[,ack-fd] or fifo:ctl-fifo[,ack-fifo] " ,
25822592 "Listen on ctl-fd descriptor for command to control measurement ('enable': enable events, 'disable': disable events).\n"
2583- "\t\t\t Optionally send control command completion ('ack\\n') to ack-fd descriptor." ,
2593+ "\t\t\t Optionally send control command completion ('ack\\n') to ack-fd descriptor.\n"
2594+ "\t\t\t Alternatively, ctl-fifo / ack-fifo will be opened and used as ctl-fd / ack-fd." ,
25842595 parse_control_option ),
25852596 OPT_END ()
25862597};
@@ -2653,12 +2664,14 @@ int cmd_record(int argc, const char **argv)
26532664 !perf_can_record_switch_events ()) {
26542665 ui__error ("kernel does not support recording context switch events\n" );
26552666 parse_options_usage (record_usage , record_options , "switch-events" , 0 );
2656- return - EINVAL ;
2667+ err = - EINVAL ;
2668+ goto out_opts ;
26572669 }
26582670
26592671 if (switch_output_setup (rec )) {
26602672 parse_options_usage (record_usage , record_options , "switch-output" , 0 );
2661- return - EINVAL ;
2673+ err = - EINVAL ;
2674+ goto out_opts ;
26622675 }
26632676
26642677 if (rec -> switch_output .time ) {
@@ -2669,8 +2682,10 @@ int cmd_record(int argc, const char **argv)
26692682 if (rec -> switch_output .num_files ) {
26702683 rec -> switch_output .filenames = calloc (sizeof (char * ),
26712684 rec -> switch_output .num_files );
2672- if (!rec -> switch_output .filenames )
2673- return - EINVAL ;
2685+ if (!rec -> switch_output .filenames ) {
2686+ err = - EINVAL ;
2687+ goto out_opts ;
2688+ }
26742689 }
26752690
26762691 /*
@@ -2686,7 +2701,8 @@ int cmd_record(int argc, const char **argv)
26862701 rec -> affinity_mask .bits = bitmap_alloc (rec -> affinity_mask .nbits );
26872702 if (!rec -> affinity_mask .bits ) {
26882703 pr_err ("Failed to allocate thread mask for %zd cpus\n" , rec -> affinity_mask .nbits );
2689- return - ENOMEM ;
2704+ err = - ENOMEM ;
2705+ goto out_opts ;
26902706 }
26912707 pr_debug2 ("thread mask[%zd]: empty\n" , rec -> affinity_mask .nbits );
26922708 }
@@ -2817,6 +2833,8 @@ int cmd_record(int argc, const char **argv)
28172833 evlist__delete (rec -> evlist );
28182834 symbol__exit ();
28192835 auxtrace_record__free (rec -> itr );
2836+ out_opts :
2837+ close_control_option (& rec -> opts );
28202838 return err ;
28212839}
28222840
0 commit comments