kernel/profile.c: simplify duplicated code in profile_setup()

The code to parse option string "schedule/sleep/kvm" of cmdline in
function profile_setup is redundant, so simplify that.

Link: https://lkml.kernel.org/r/20220901003121.53597-1-wuchi.zero@gmail.com
Signed-off-by: wuchi <wuchi.zero@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foudation.org>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
wuchi 2022-09-01 08:31:21 +08:00 committed by Andrew Morton
parent 63095f4f3a
commit 35783ccbe5

View File

@ -59,43 +59,39 @@ int profile_setup(char *str)
static const char schedstr[] = "schedule"; static const char schedstr[] = "schedule";
static const char sleepstr[] = "sleep"; static const char sleepstr[] = "sleep";
static const char kvmstr[] = "kvm"; static const char kvmstr[] = "kvm";
const char *select = NULL;
int par; int par;
if (!strncmp(str, sleepstr, strlen(sleepstr))) { if (!strncmp(str, sleepstr, strlen(sleepstr))) {
#ifdef CONFIG_SCHEDSTATS #ifdef CONFIG_SCHEDSTATS
force_schedstat_enabled(); force_schedstat_enabled();
prof_on = SLEEP_PROFILING; prof_on = SLEEP_PROFILING;
if (str[strlen(sleepstr)] == ',') select = sleepstr;
str += strlen(sleepstr) + 1;
if (get_option(&str, &par))
prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
pr_info("kernel sleep profiling enabled (shift: %u)\n",
prof_shift);
#else #else
pr_warn("kernel sleep profiling requires CONFIG_SCHEDSTATS\n"); pr_warn("kernel sleep profiling requires CONFIG_SCHEDSTATS\n");
#endif /* CONFIG_SCHEDSTATS */ #endif /* CONFIG_SCHEDSTATS */
} else if (!strncmp(str, schedstr, strlen(schedstr))) { } else if (!strncmp(str, schedstr, strlen(schedstr))) {
prof_on = SCHED_PROFILING; prof_on = SCHED_PROFILING;
if (str[strlen(schedstr)] == ',') select = schedstr;
str += strlen(schedstr) + 1;
if (get_option(&str, &par))
prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
pr_info("kernel schedule profiling enabled (shift: %u)\n",
prof_shift);
} else if (!strncmp(str, kvmstr, strlen(kvmstr))) { } else if (!strncmp(str, kvmstr, strlen(kvmstr))) {
prof_on = KVM_PROFILING; prof_on = KVM_PROFILING;
if (str[strlen(kvmstr)] == ',') select = kvmstr;
str += strlen(kvmstr) + 1;
if (get_option(&str, &par))
prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
pr_info("kernel KVM profiling enabled (shift: %u)\n",
prof_shift);
} else if (get_option(&str, &par)) { } else if (get_option(&str, &par)) {
prof_shift = clamp(par, 0, BITS_PER_LONG - 1); prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
prof_on = CPU_PROFILING; prof_on = CPU_PROFILING;
pr_info("kernel profiling enabled (shift: %u)\n", pr_info("kernel profiling enabled (shift: %u)\n",
prof_shift); prof_shift);
} }
if (select) {
if (str[strlen(select)] == ',')
str += strlen(select) + 1;
if (get_option(&str, &par))
prof_shift = clamp(par, 0, BITS_PER_LONG - 1);
pr_info("kernel %s profiling enabled (shift: %u)\n",
select, prof_shift);
}
return 1; return 1;
} }
__setup("profile=", profile_setup); __setup("profile=", profile_setup);