1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc.
6 #ifndef __CPUIDLE_INFO_HW__
7 #define __CPUIDLE_INFO_HW__
12 #include "idle_monitor/idle_monitors.h"
14 #define MONITORS_MAX 20
15 #define MONITOR_NAME_LEN 20
17 /* CSTATE_NAME_LEN is limited by header field width defined
18 * in cpupower-monitor.c. Header field width is defined to be
19 * sum of percent width and two spaces for padding.
22 #define CSTATE_NAME_LEN 7
24 #define CSTATE_NAME_LEN 5
26 #define CSTATE_DESC_LEN 60
30 /* Hard to define the right names ...: */
32 RANGE_THREAD, /* Lowest in topology hierarcy, AMD: core, Intel: thread
34 RANGE_CORE, /* AMD: unit, Intel: core, kernel_sysfs: core_id */
35 RANGE_PACKAGE, /* Package, processor socket */
36 RANGE_MACHINE, /* Machine, platform wide */
39 typedef struct cstate {
41 enum power_range_e range;
42 char name[CSTATE_NAME_LEN];
43 char desc[CSTATE_DESC_LEN];
45 /* either provide a percentage or a general count */
46 int (*get_count_percent)(unsigned int self_id, double *percent,
48 int (*get_count)(unsigned int self_id, unsigned long long *count,
52 struct cpuidle_monitor {
53 /* Name must not contain whitespaces */
54 char name[MONITOR_NAME_LEN];
60 struct cpuidle_monitor* (*do_register) (void);
61 void (*unregister)(void);
62 unsigned int overflow_s;
64 unsigned int needs_root:1;
65 unsigned int per_cpu_schedule:1;
69 extern long long timespec_diff_us(struct timespec start, struct timespec end);
71 #define print_overflow_err(mes, ov) \
73 fprintf(stderr, gettext("Measure took %u seconds, but registers could " \
74 "overflow at %u seconds, results " \
75 "could be inaccurate\n"), mes, ov); \
79 /* Taken over from x86info project sources -> return 0 on success */
81 #include <sys/types.h>
83 static inline int bind_cpu(int cpu)
87 if (sched_getaffinity(getpid(), sizeof(set), &set) == 0) {
90 return sched_setaffinity(getpid(), sizeof(set), &set);
95 #endif /* __CPUIDLE_INFO_HW__ */