summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 807a30e)
raw | patch | inline | side by side (parent: 807a30e)
author | Vincent Brillault <git@lerya.net> | |
Thu, 16 Apr 2015 19:23:47 +0000 (21:23 +0200) | ||
committer | Vincent Brillault <git@lerya.net> | |
Thu, 16 Apr 2015 19:23:47 +0000 (21:23 +0200) |
Use unsigned integers to reprensent the cpu, core and package
numbers. Do not set it to -1 at init time.
numbers. Do not set it to -1 at init time.
src/turbostat.c | patch | blob | history |
diff --git a/src/turbostat.c b/src/turbostat.c
index f3be6020aaa37575f56ef0039d900d8d6c5bb1e7..76b65cb64b1efed2e8fcf9afacd9daedef454ae3 100644 (file)
--- a/src/turbostat.c
+++ b/src/turbostat.c
#define GET_PKG(pkg_base, pkg_no) (pkg_base + pkg_no)
struct cpu_topology {
- int package_id;
- int core_id;
+ unsigned int package_id;
+ unsigned int core_id;
_Bool first_core_in_package;
_Bool first_thread_in_core;
};
static struct topology {
- int max_cpu_id;
- int num_packages;
- int num_cores;
- int num_threads;
+ unsigned int max_cpu_id;
+ unsigned int num_packages;
+ unsigned int num_cores;
+ unsigned int num_threads;
struct cpu_topology *cpus;
} topology;
* Can change the scheduling affinity of the current process if multiple_read is 1
*/
static int __attribute__((warn_unused_result))
-open_msr(int cpu, _Bool multiple_read)
+open_msr(unsigned int cpu, _Bool multiple_read)
{
char pathname[32];
int fd;
* This call will not affect the scheduling affinity of this thread.
*/
static int __attribute__((warn_unused_result))
-get_msr(int cpu, off_t offset, unsigned long long *msr)
+get_msr(unsigned int cpu, off_t offset, unsigned long long *msr)
{
ssize_t retval;
int fd;
static int __attribute__((warn_unused_result))
get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
{
- int cpu = t->cpu_id;
+ unsigned int cpu = t->cpu_id;
unsigned long long msr;
int msr_fd;
int retval = 0;
* Check if a given cpu id is in our compiled list of existing CPUs
*/
static int
-cpu_is_not_present(int cpu)
+cpu_is_not_present(unsigned int cpu)
{
return !CPU_ISSET_S(cpu, cpu_present_setsize, cpu_present_set);
}
for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_data *),
struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
{
- int retval, pkg_no, core_no, thread_no;
+ int retval;
+ unsigned int pkg_no, core_no, thread_no;
for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
for (core_no = 0; core_no < topology.num_cores; ++core_no) {
for_all_cpus_delta(const struct thread_data *thread_new_base, const struct core_data *core_new_base, const struct pkg_data *pkg_new_base,
const struct thread_data *thread_old_base, const struct core_data *core_old_base, const struct pkg_data *pkg_old_base)
{
- int retval, pkg_no, core_no, thread_no;
+ int retval;
+ unsigned int pkg_no, core_no, thread_no;
for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
for (core_no = 0; core_no < topology.num_cores; ++core_no) {
}
static int
-get_threads_on_core(int cpu)
+get_threads_on_core(unsigned int cpu)
{
char path[80];
FILE *filep;
* return max_cpu number
*/
static int __attribute__((warn_unused_result))
-for_all_proc_cpus(int (func)(int))
+for_all_proc_cpus(int (func)(unsigned int))
{
FILE *fp;
- int cpu_num;
+ unsigned int cpu_num;
int retval;
fp = fopen("/proc/stat", "r");
* Update the stored topology.max_cpu_id
*/
static int
-update_max_cpu_id(int cpu)
+update_max_cpu_id(unsigned int cpu)
{
if (topology.max_cpu_id < cpu)
topology.max_cpu_id = cpu;
}
static int
-mark_cpu_present(int cpu)
+mark_cpu_present(unsigned int cpu)
{
CPU_SET_S(cpu, cpu_present_setsize, cpu_present_set);
return 0;
static int __attribute__((warn_unused_result))
topology_probe()
{
- int i;
+ unsigned int i;
int ret;
- int max_package_id, max_core_id, max_thread_id;
+ unsigned int max_package_id, max_core_id, max_thread_id;
max_package_id = max_core_id = max_thread_id = 0;
/* Clean topology */
* find max_core_id, max_package_id
*/
for (i = 0; i <= topology.max_cpu_id; ++i) {
- int num_threads;
+ unsigned int num_threads;
struct cpu_topology *cpu = &topology.cpus[i];
if (cpu_is_not_present(i)) {
if (ret < 0)
goto err;
else
- cpu->package_id = ret;
+ cpu->package_id = (unsigned int) ret;
if (cpu->package_id > max_package_id)
max_package_id = cpu->package_id;
if (ret < 0)
goto err;
else
- cpu->core_id = ret;
+ cpu->core_id = (unsigned int) ret;
if (cpu->core_id > max_core_id)
max_core_id = cpu->core_id;
ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/core_siblings_list", i);
if (ret < 0)
goto err;
- else if (ret == i)
+ else if ((unsigned int) ret == i)
cpu->first_core_in_package = 1;
ret = get_threads_on_core(i);
if (ret < 0)
goto err;
else
- num_threads = ret;
+ num_threads = (unsigned int) ret;
if (num_threads > max_thread_id)
max_thread_id = num_threads;
ret = parse_int_file("/sys/devices/system/cpu/cpu%d/topology/thread_siblings_list", i);
if (ret < 0)
goto err;
- else if (ret == i)
+ else if ((unsigned int) ret == i)
cpu->first_thread_in_core = 1;
DEBUG("Turbostat plugin: cpu %d pkg %d core %d\n",
static int
allocate_counters(struct thread_data **threads, struct core_data **cores, struct pkg_data **packages)
{
- int i;
- int total_threads, total_cores;
+ unsigned int i;
+ unsigned int total_threads, total_cores;
total_threads = topology.num_threads * topology.num_cores * topology.num_packages;
*threads = calloc(total_threads, sizeof(struct thread_data));
if (*threads == NULL)
goto err;
- for (i = 0; i < total_threads; ++i)
- (*threads)[i].cpu_id = -1;
-
total_cores = topology.num_cores * topology.num_packages;
*cores = calloc(total_cores, sizeof(struct core_data));
if (*cores == NULL)
goto err_clean_threads;
- for (i = 0; i < total_cores; ++i)
- (*cores)[i].core_id = -1;
-
*packages = calloc(topology.num_packages, sizeof(struct pkg_data));
if (*packages == NULL)
goto err_clean_cores;
static void
init_counter(struct thread_data *thread_base, struct core_data *core_base,
- struct pkg_data *pkg_base, int cpu_id)
+ struct pkg_data *pkg_base, unsigned int cpu_id)
{
struct thread_data *t;
struct core_data *c;
static void
initialize_counters(void)
{
- int cpu_id;
+ unsigned int cpu_id;
for (cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) {
if (cpu_is_not_present(cpu_id))