Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/top/machine.c
Show First 20 Lines • Show All 205 Lines • ▼ Show 20 Lines | |||||
static int ncpus; | static int ncpus; | ||||
static unsigned long cpumask; | static unsigned long cpumask; | ||||
static long *times; | static long *times; | ||||
static long *pcpu_cp_time; | static long *pcpu_cp_time; | ||||
static long *pcpu_cp_old; | static long *pcpu_cp_old; | ||||
static long *pcpu_cp_diff; | static long *pcpu_cp_diff; | ||||
static int *pcpu_cpu_states; | static int *pcpu_cpu_states; | ||||
/* Battery units and states */ | |||||
static int battery_units; | |||||
static int battery_life; | |||||
static int compare_swap(const void *a, const void *b); | static int compare_swap(const void *a, const void *b); | ||||
static int compare_jid(const void *a, const void *b); | static int compare_jid(const void *a, const void *b); | ||||
static int compare_pid(const void *a, const void *b); | static int compare_pid(const void *a, const void *b); | ||||
static int compare_tid(const void *a, const void *b); | static int compare_tid(const void *a, const void *b); | ||||
static const char *format_nice(const struct kinfo_proc *pp); | static const char *format_nice(const struct kinfo_proc *pp); | ||||
static void getsysctl(const char *name, void *ptr, size_t len); | static void getsysctl(const char *name, void *ptr, size_t len); | ||||
static int swapmode(int *retavail, int *retfree); | static int swapmode(int *retavail, int *retfree); | ||||
static void update_layout(void); | static void update_layout(void); | ||||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Lines | for (i = 0; i <= maxid; i++) { | ||||
} | } | ||||
} | } | ||||
assert(ncpus > 0); | assert(ncpus > 0); | ||||
pcpu_cp_old = calloc(ncpus * CPUSTATES, sizeof(long)); | pcpu_cp_old = calloc(ncpus * CPUSTATES, sizeof(long)); | ||||
pcpu_cp_diff = calloc(ncpus * CPUSTATES, sizeof(long)); | pcpu_cp_diff = calloc(ncpus * CPUSTATES, sizeof(long)); | ||||
pcpu_cpu_states = calloc(ncpus * CPUSTATES, sizeof(int)); | pcpu_cpu_states = calloc(ncpus * CPUSTATES, sizeof(int)); | ||||
statics->ncpus = ncpus; | statics->ncpus = ncpus; | ||||
/* Allocate state of battery units. */ | |||||
battery_units = 0; | |||||
size = sizeof(int); | |||||
sysctlbyname("hw.acpi.battery.units", &battery_units, &size, NULL, 0); | |||||
statics->nbatteries = battery_units; | |||||
imp: It would be nice to have a quick comment here saying that only batteries reported via ACPI are… | |||||
Done Inline ActionsShould I try running this on a Pinebook? I know someone in the city who has one. antranigv_freebsd.am: Should I try running this on a Pinebook? I know someone in the city who has one. | |||||
update_layout(); | update_layout(); | ||||
/* all done! */ | /* all done! */ | ||||
return (0); | return (0); | ||||
} | } | ||||
char * | char * | ||||
format_header(const char *uname_field) | format_header(const char *uname_field) | ||||
▲ Show 20 Lines • Show All 190 Lines • ▼ Show 20 Lines | get_system_info(struct system_info *si) | ||||
mib[1] = KERN_BOOTTIME; | mib[1] = KERN_BOOTTIME; | ||||
size = sizeof(boottime); | size = sizeof(boottime); | ||||
if (sysctl(mib, nitems(mib), &boottime, &size, NULL, 0) != -1 && | if (sysctl(mib, nitems(mib), &boottime, &size, NULL, 0) != -1 && | ||||
boottime.tv_sec != 0) { | boottime.tv_sec != 0) { | ||||
si->boottime = boottime; | si->boottime = boottime; | ||||
} else { | } else { | ||||
si->boottime.tv_sec = -1; | si->boottime.tv_sec = -1; | ||||
} | } | ||||
battery_life = 0; | |||||
if (battery_units > 0) { | |||||
GETSYSCTL("hw.acpi.battery.life", battery_life); | |||||
} | |||||
si->battery = battery_life; | |||||
} | } | ||||
#define NOPROC ((void *)-1) | #define NOPROC ((void *)-1) | ||||
/* | /* | ||||
* We need to compare data from the old process entry with the new | * We need to compare data from the old process entry with the new | ||||
* process entry. | * process entry. | ||||
* To facilitate doing this quickly we stash a pointer in the kinfo_proc | * To facilitate doing this quickly we stash a pointer in the kinfo_proc | ||||
▲ Show 20 Lines • Show All 972 Lines • Show Last 20 Lines |
It would be nice to have a quick comment here saying that only batteries reported via ACPI are counted. Anybody still running APM won't have these numbers, but that's totally fine: APM is likely to be deleted soon anyway as laptops that require you use APM aren't really viable anymore as laptops... I'm also unsure how the 'pinebook' reports this information, but that too is a niche thing that's kinda weird still.... So just a quick comment will suffice.