Index: usr.bin/top/machine.c =================================================================== --- usr.bin/top/machine.c +++ usr.bin/top/machine.c @@ -196,7 +196,7 @@ static const char *ordernames[] = { "cpu", "size", "res", "time", "pri", "threads", "total", "read", "write", "fault", "vcsw", "ivcsw", - "jid", "swap", "pid", NULL + "jid", "swap", "core", "pid", NULL }; /* Per-cpu time states */ @@ -214,6 +214,7 @@ static int compare_jid(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_core(const void *a, const void *b); static const char *format_nice(const struct kinfo_proc *pp); static void getsysctl(const char *name, void *ptr, size_t len); static int swapmode(int *retavail, int *retfree); @@ -1276,6 +1277,21 @@ return (diff > 0 ? 1 : -1); \ } while (0) +#define ORDERKEY_CORE(a, b) do { \ + int cpu1, cpu2; \ + if ((int)(a)->ki_stat == SRUN && (int)(a)->ki_oncpu != NOCPU) \ + cpu1 = (int)(a)->ki_oncpu; \ + else \ + cpu1 = (int)(a)->ki_lastcpu; \ + if ((int)(b)->ki_stat == SRUN && (int)(b)->ki_oncpu != NOCPU) \ + cpu2 = (int)(b)->ki_oncpu; \ + else \ + cpu2 = (int)(b)->ki_lastcpu; \ + int diff = cpu2 - cpu1; \ + if (diff != 0) \ + return (diff > 0 ? 1 : -1); \ +} while (0) + /* compare_cpu - the comparison function for sorting by cpu percentage */ static int @@ -1294,6 +1310,25 @@ return (0); } +/* compare_core - the comparison function for sorting by cpu core number */ + +static int +compare_core(const void *arg1, const void *arg2) +{ + const struct kinfo_proc *p1 = *(const struct kinfo_proc * const *)arg1; + const struct kinfo_proc *p2 = *(const struct kinfo_proc * const *)arg2; + + ORDERKEY_CORE(p1, p2); + ORDERKEY_PCTCPU(p1, p2); + ORDERKEY_CPTICKS(p1, p2); + ORDERKEY_STATE(p1, p2); + ORDERKEY_PRIO(p1, p2); + ORDERKEY_RSSIZE(p1, p2); + + return(0); +} + + /* compare_size - the comparison function for sorting by total memory usage */ static int @@ -1511,6 +1546,7 @@ compare_ivcsw, compare_jid, compare_swap, + compare_core, NULL }; Index: usr.bin/top/top.1 =================================================================== --- usr.bin/top/top.1 +++ usr.bin/top/top.1 @@ -1,5 +1,5 @@ .\" $FreeBSD$ -.Dd October 2, 2018 +.Dd December 10, 2018 .Dt TOP 1 .Os .Sh NAME @@ -153,7 +153,7 @@ \*(lqcpu\*(lq, \*(rqsize\*(lq, \*(rqres\*(lq, \*(rqtime\*(lq, \*(rqpri\*(lq, \*(rqthreads\*(lq, \*(lqtotal\*(lq, \*(rqread\*(lq, \*(rqwrite\*(lq, \*(rqfault\*(lq, \*(rqvcsw\*(lq, \*(rqivcsw\*(lq, -\*(lqjid\*(lq, \*(rqswap\*(lq or \*(rqpid\*(lq. +\*(lqjid\*(lq, \*(rqswap\*(lq, \*(rqcore\*(lq, or \*(rqpid\*(lq. .It Fl p Ar pid Show only the process .Ar pid .