Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf daemon: Use control to stop session

Use the 'stop' control command to stop perf record session. If that
fails, fall back to current SIGTERM/SIGKILL pair.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexei Budankov <abudankov@huawei.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: https://lore.kernel.org/r/20210208200908.1019149-17-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
6d6162d5 edcaa479

+46 -10
+46 -10
tools/perf/builtin-daemon.c
··· 870 870 static void daemon_session__kill(struct daemon_session *session, 871 871 struct daemon *daemon) 872 872 { 873 - daemon_session__signal(session, SIGTERM); 874 - if (daemon_session__wait(session, daemon, 10)) { 875 - daemon_session__signal(session, SIGKILL); 876 - daemon_session__wait(session, daemon, 10); 877 - } 873 + int how = 0; 874 + 875 + do { 876 + switch (how) { 877 + case 0: 878 + daemon_session__control(session, "stop", false); 879 + break; 880 + case 1: 881 + daemon_session__signal(session, SIGTERM); 882 + break; 883 + case 2: 884 + daemon_session__signal(session, SIGKILL); 885 + break; 886 + default: 887 + break; 888 + } 889 + how++; 890 + 891 + } while (daemon_session__wait(session, daemon, 10)); 878 892 } 879 893 880 894 static void daemon__signal(struct daemon *daemon, int sig) ··· 913 899 daemon_session__delete(session); 914 900 } 915 901 902 + static void daemon__stop(struct daemon *daemon) 903 + { 904 + struct daemon_session *session; 905 + 906 + list_for_each_entry(session, &daemon->sessions, list) 907 + daemon_session__control(session, "stop", false); 908 + } 909 + 916 910 static void daemon__kill(struct daemon *daemon) 917 911 { 918 - daemon__signal(daemon, SIGTERM); 919 - if (daemon__wait(daemon, 10)) { 920 - daemon__signal(daemon, SIGKILL); 921 - daemon__wait(daemon, 10); 922 - } 912 + int how = 0; 913 + 914 + do { 915 + switch (how) { 916 + case 0: 917 + daemon__stop(daemon); 918 + break; 919 + case 1: 920 + daemon__signal(daemon, SIGTERM); 921 + break; 922 + case 2: 923 + daemon__signal(daemon, SIGKILL); 924 + break; 925 + default: 926 + break; 927 + } 928 + how++; 929 + 930 + } while (daemon__wait(daemon, 10)); 923 931 } 924 932 925 933 static void daemon__exit(struct daemon *daemon)