Skip to content

Commit c6fafe3

Browse files
captain5050acmel
authored andcommitted
perf header: Move is_cpu_online to numa bench
The helper function is only used in the NUMA benchmark as typically online CPUs are determined through perf_cpu_map__new_online_cpus(). Reduce the scope of the function for now. Reviewed-by: James Clark <[email protected]> Signed-off-by: Ian Rogers <[email protected]> Tested-by: Xu Yang <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Albert Ou <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Athira Rajeev <[email protected]> Cc: Ben Zong-You Xie <[email protected]> Cc: Benjamin Gray <[email protected]> Cc: Bibo Mao <[email protected]> Cc: Clément Le Goffic <[email protected]> Cc: Dima Kogan <[email protected]> Cc: Dr. David Alan Gilbert <[email protected]> Cc: Huacai Chen <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Garry <[email protected]> Cc: Kan Liang <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Mike Leach <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ravi Bangoria <[email protected]> Cc: Sandipan Das <[email protected]> Cc: Will Deacon <[email protected]> Cc: Yicong Yang <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 4a159e6 commit c6fafe3

File tree

3 files changed

+53
-52
lines changed

3 files changed

+53
-52
lines changed

tools/perf/bench/numa.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sys/resource.h>
2828
#include <sys/wait.h>
2929
#include <sys/prctl.h>
30+
#include <sys/stat.h>
3031
#include <sys/types.h>
3132
#include <linux/kernel.h>
3233
#include <linux/time64.h>
@@ -35,6 +36,7 @@
3536

3637
#include "../util/header.h"
3738
#include "../util/mutex.h"
39+
#include <api/fs/fs.h>
3840
#include <numa.h>
3941
#include <numaif.h>
4042

@@ -533,6 +535,57 @@ static int parse_cpu_list(const char *arg)
533535
return 0;
534536
}
535537

538+
/*
539+
* Check whether a CPU is online
540+
*
541+
* Returns:
542+
* 1 -> if CPU is online
543+
* 0 -> if CPU is offline
544+
* -1 -> error case
545+
*/
546+
static int is_cpu_online(unsigned int cpu)
547+
{
548+
char *str;
549+
size_t strlen;
550+
char buf[256];
551+
int status = -1;
552+
struct stat statbuf;
553+
554+
snprintf(buf, sizeof(buf),
555+
"/sys/devices/system/cpu/cpu%d", cpu);
556+
if (stat(buf, &statbuf) != 0)
557+
return 0;
558+
559+
/*
560+
* Check if /sys/devices/system/cpu/cpux/online file
561+
* exists. Some cases cpu0 won't have online file since
562+
* it is not expected to be turned off generally.
563+
* In kernels without CONFIG_HOTPLUG_CPU, this
564+
* file won't exist
565+
*/
566+
snprintf(buf, sizeof(buf),
567+
"/sys/devices/system/cpu/cpu%d/online", cpu);
568+
if (stat(buf, &statbuf) != 0)
569+
return 1;
570+
571+
/*
572+
* Read online file using sysfs__read_str.
573+
* If read or open fails, return -1.
574+
* If read succeeds, return value from file
575+
* which gets stored in "str"
576+
*/
577+
snprintf(buf, sizeof(buf),
578+
"devices/system/cpu/cpu%d/online", cpu);
579+
580+
if (sysfs__read_str(buf, &str, &strlen) < 0)
581+
return status;
582+
583+
status = atoi(str);
584+
585+
free(str);
586+
return status;
587+
}
588+
536589
static int parse_setup_cpu_list(void)
537590
{
538591
struct thread_data *td;

tools/perf/util/header.c

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -987,57 +987,6 @@ static int write_dir_format(struct feat_fd *ff,
987987
return do_write(ff, &data->dir.version, sizeof(data->dir.version));
988988
}
989989

990-
/*
991-
* Check whether a CPU is online
992-
*
993-
* Returns:
994-
* 1 -> if CPU is online
995-
* 0 -> if CPU is offline
996-
* -1 -> error case
997-
*/
998-
int is_cpu_online(unsigned int cpu)
999-
{
1000-
char *str;
1001-
size_t strlen;
1002-
char buf[256];
1003-
int status = -1;
1004-
struct stat statbuf;
1005-
1006-
snprintf(buf, sizeof(buf),
1007-
"/sys/devices/system/cpu/cpu%d", cpu);
1008-
if (stat(buf, &statbuf) != 0)
1009-
return 0;
1010-
1011-
/*
1012-
* Check if /sys/devices/system/cpu/cpux/online file
1013-
* exists. Some cases cpu0 won't have online file since
1014-
* it is not expected to be turned off generally.
1015-
* In kernels without CONFIG_HOTPLUG_CPU, this
1016-
* file won't exist
1017-
*/
1018-
snprintf(buf, sizeof(buf),
1019-
"/sys/devices/system/cpu/cpu%d/online", cpu);
1020-
if (stat(buf, &statbuf) != 0)
1021-
return 1;
1022-
1023-
/*
1024-
* Read online file using sysfs__read_str.
1025-
* If read or open fails, return -1.
1026-
* If read succeeds, return value from file
1027-
* which gets stored in "str"
1028-
*/
1029-
snprintf(buf, sizeof(buf),
1030-
"devices/system/cpu/cpu%d/online", cpu);
1031-
1032-
if (sysfs__read_str(buf, &str, &strlen) < 0)
1033-
return status;
1034-
1035-
status = atoi(str);
1036-
1037-
free(str);
1038-
return status;
1039-
}
1040-
1041990
#ifdef HAVE_LIBBPF_SUPPORT
1042991
static int write_bpf_prog_info(struct feat_fd *ff,
1043992
struct evlist *evlist __maybe_unused)

tools/perf/util/header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ int write_padded(struct feat_fd *fd, const void *bf,
196196

197197
#define MAX_CACHE_LVL 4
198198

199-
int is_cpu_online(unsigned int cpu);
200199
int build_caches_for_cpu(u32 cpu, struct cpu_cache_level caches[], u32 *cntp);
201200

202201
/*

0 commit comments

Comments
 (0)