turbostat.c (d743dae6d1936160366a32f3400f03db1da9421b) turbostat.c (d4794f25f122aa1a8a073be51112edaa723ffff4)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * turbostat -- show CPU frequency and C-state residency
4 * on modern Intel and AMD processors.
5 *
6 * Copyright (c) 2013 Intel Corporation.
7 * Len Brown <len.brown@intel.com>
8 */

--- 152 unchanged lines hidden (view full) ---

161size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size;
162#define MAX_ADDED_COUNTERS 8
163#define MAX_ADDED_THREAD_COUNTERS 24
164#define BITMASK_SIZE 32
165
166struct thread_data {
167 struct timeval tv_begin;
168 struct timeval tv_end;
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * turbostat -- show CPU frequency and C-state residency
4 * on modern Intel and AMD processors.
5 *
6 * Copyright (c) 2013 Intel Corporation.
7 * Len Brown <len.brown@intel.com>
8 */

--- 152 unchanged lines hidden (view full) ---

161size_t cpu_present_setsize, cpu_affinity_setsize, cpu_subset_size;
162#define MAX_ADDED_COUNTERS 8
163#define MAX_ADDED_THREAD_COUNTERS 24
164#define BITMASK_SIZE 32
165
166struct thread_data {
167 struct timeval tv_begin;
168 struct timeval tv_end;
169 struct timeval tv_delta;
169 unsigned long long tsc;
170 unsigned long long aperf;
171 unsigned long long mperf;
172 unsigned long long c1;
173 unsigned long long irq_count;
174 unsigned int smi_count;
175 unsigned int cpu_id;
176 unsigned int apic_id;

--- 728 unchanged lines hidden (view full) ---

905 timersub(&t->tv_end, &t->tv_begin, &tv);
906 outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec);
907 }
908
909 /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */
910 if (DO_BIC(BIC_TOD))
911 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec);
912
170 unsigned long long tsc;
171 unsigned long long aperf;
172 unsigned long long mperf;
173 unsigned long long c1;
174 unsigned long long irq_count;
175 unsigned int smi_count;
176 unsigned int cpu_id;
177 unsigned int apic_id;

--- 728 unchanged lines hidden (view full) ---

906 timersub(&t->tv_end, &t->tv_begin, &tv);
907 outp += sprintf(outp, "%5ld\t", tv.tv_sec * 1000000 + tv.tv_usec);
908 }
909
910 /* Time_Of_Day_Seconds: on each row, print sec.usec last timestamp taken */
911 if (DO_BIC(BIC_TOD))
912 outp += sprintf(outp, "%10ld.%06ld\t", t->tv_end.tv_sec, t->tv_end.tv_usec);
913
913 interval_float = tv_delta.tv_sec + tv_delta.tv_usec/1000000.0;
914 interval_float = t->tv_delta.tv_sec + t->tv_delta.tv_usec/1000000.0;
914
915 tsc = t->tsc * tsc_tweak;
916
917 /* topo columns, print blanks on 1st (average) line */
918 if (t == &average.threads) {
919 if (DO_BIC(BIC_Package))
920 outp += sprintf(outp, "%s-", (printed++ ? delim : ""));
921 if (DO_BIC(BIC_Die))

--- 381 unchanged lines hidden (view full) ---

1303 new->x2apic_id = old->x2apic_id;
1304
1305 /*
1306 * the timestamps from start of measurement interval are in "old"
1307 * the timestamp from end of measurement interval are in "new"
1308 * over-write old w/ new so we can print end of interval values
1309 */
1310
915
916 tsc = t->tsc * tsc_tweak;
917
918 /* topo columns, print blanks on 1st (average) line */
919 if (t == &average.threads) {
920 if (DO_BIC(BIC_Package))
921 outp += sprintf(outp, "%s-", (printed++ ? delim : ""));
922 if (DO_BIC(BIC_Die))

--- 381 unchanged lines hidden (view full) ---

1304 new->x2apic_id = old->x2apic_id;
1305
1306 /*
1307 * the timestamps from start of measurement interval are in "old"
1308 * the timestamp from end of measurement interval are in "new"
1309 * over-write old w/ new so we can print end of interval values
1310 */
1311
1312 timersub(&new->tv_begin, &old->tv_begin, &old->tv_delta);
1311 old->tv_begin = new->tv_begin;
1312 old->tv_end = new->tv_end;
1313
1314 old->tsc = new->tsc - old->tsc;
1315
1316 /* check for TSC < 1 Mcycles over interval */
1317 if (old->tsc < (1000 * 1000))
1318 errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n"

--- 79 unchanged lines hidden (view full) ---

1398{
1399 int i;
1400 struct msr_counter *mp;
1401
1402 t->tv_begin.tv_sec = 0;
1403 t->tv_begin.tv_usec = 0;
1404 t->tv_end.tv_sec = 0;
1405 t->tv_end.tv_usec = 0;
1313 old->tv_begin = new->tv_begin;
1314 old->tv_end = new->tv_end;
1315
1316 old->tsc = new->tsc - old->tsc;
1317
1318 /* check for TSC < 1 Mcycles over interval */
1319 if (old->tsc < (1000 * 1000))
1320 errx(-3, "Insanely slow TSC rate, TSC stops in idle?\n"

--- 79 unchanged lines hidden (view full) ---

1400{
1401 int i;
1402 struct msr_counter *mp;
1403
1404 t->tv_begin.tv_sec = 0;
1405 t->tv_begin.tv_usec = 0;
1406 t->tv_end.tv_sec = 0;
1407 t->tv_end.tv_usec = 0;
1408 t->tv_delta.tv_sec = 0;
1409 t->tv_delta.tv_usec = 0;
1406
1407 t->tsc = 0;
1408 t->aperf = 0;
1409 t->mperf = 0;
1410 t->c1 = 0;
1411
1412 t->irq_count = 0;
1413 t->smi_count = 0;

--- 153 unchanged lines hidden (view full) ---

1567{
1568 int i;
1569 struct msr_counter *mp;
1570
1571 clear_counters(&average.threads, &average.cores, &average.packages);
1572
1573 for_all_cpus(sum_counters, t, c, p);
1574
1410
1411 t->tsc = 0;
1412 t->aperf = 0;
1413 t->mperf = 0;
1414 t->c1 = 0;
1415
1416 t->irq_count = 0;
1417 t->smi_count = 0;

--- 153 unchanged lines hidden (view full) ---

1571{
1572 int i;
1573 struct msr_counter *mp;
1574
1575 clear_counters(&average.threads, &average.cores, &average.packages);
1576
1577 for_all_cpus(sum_counters, t, c, p);
1578
1579 /* Use the global time delta for the average. */
1580 average.threads.tv_delta = tv_delta;
1581
1575 average.threads.tsc /= topo.num_cpus;
1576 average.threads.aperf /= topo.num_cpus;
1577 average.threads.mperf /= topo.num_cpus;
1578 average.threads.c1 /= topo.num_cpus;
1579
1580 if (average.threads.irq_count > 9999999)
1581 sums_need_wide_columns = 1;
1582

--- 173 unchanged lines hidden (view full) ---

1756int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
1757{
1758 int cpu = t->cpu_id;
1759 unsigned long long msr;
1760 int aperf_mperf_retry_count = 0;
1761 struct msr_counter *mp;
1762 int i;
1763
1582 average.threads.tsc /= topo.num_cpus;
1583 average.threads.aperf /= topo.num_cpus;
1584 average.threads.mperf /= topo.num_cpus;
1585 average.threads.c1 /= topo.num_cpus;
1586
1587 if (average.threads.irq_count > 9999999)
1588 sums_need_wide_columns = 1;
1589

--- 173 unchanged lines hidden (view full) ---

1763int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
1764{
1765 int cpu = t->cpu_id;
1766 unsigned long long msr;
1767 int aperf_mperf_retry_count = 0;
1768 struct msr_counter *mp;
1769 int i;
1770
1764 gettimeofday(&t->tv_begin, (struct timezone *)NULL);
1765
1766 if (cpu_migrate(cpu)) {
1767 fprintf(outf, "Could not migrate to CPU %d\n", cpu);
1768 return -1;
1769 }
1770
1771 if (cpu_migrate(cpu)) {
1772 fprintf(outf, "Could not migrate to CPU %d\n", cpu);
1773 return -1;
1774 }
1775
1776 gettimeofday(&t->tv_begin, (struct timezone *)NULL);
1777
1771 if (first_counter_read)
1772 get_apic_id(t);
1773retry:
1774 t->tsc = rdtsc(); /* we are running on local CPU of interest */
1775
1776 if (DO_BIC(BIC_Avg_MHz) || DO_BIC(BIC_Busy) || DO_BIC(BIC_Bzy_MHz)) {
1777 unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time;
1778

--- 3980 unchanged lines hidden ---
1778 if (first_counter_read)
1779 get_apic_id(t);
1780retry:
1781 t->tsc = rdtsc(); /* we are running on local CPU of interest */
1782
1783 if (DO_BIC(BIC_Avg_MHz) || DO_BIC(BIC_Busy) || DO_BIC(BIC_Bzy_MHz)) {
1784 unsigned long long tsc_before, tsc_between, tsc_after, aperf_time, mperf_time;
1785

--- 3980 unchanged lines hidden ---