2 * top - a top users display for Unix
4 * SYNOPSIS: For DragonFly 2.x and later
7 * Originally written for BSD4.4 system by Christos Zoulas.
8 * Ported to FreeBSD 2.x by Steven Wallace && Wolfram Schneider
9 * Order support hacked in from top-3.5beta6/machine/m_aix41.c
10 * by Monte Mitzelfelt (for latest top see http://www.groupsys.com/topinfo/)
12 * This is the machine-dependent module for DragonFly 2.5.1
14 * DragonFly 2.x and above
18 * AUTHOR: Jan Lentfer <Jan.Lentfer@web.de>
19 * This module has been put together from different sources and is based on the
20 * work of many other people, e.g. Matthew Dillon, Simon Schubert, Jordan Gordeev.
22 * $FreeBSD: src/usr.bin/top/machine.c,v 1.29.2.2 2001/07/31 20:27:05 tmm Exp $
26 #include <sys/types.h>
28 #include <sys/signal.h>
29 #include <sys/param.h>
38 #include <sys/errno.h>
39 #include <sys/sysctl.h>
41 #include <sys/vmmeter.h>
42 #include <sys/resource.h>
43 #include <sys/rtprio.h>
49 #include <osreldate.h> /* for changes in kernel structures */
51 #include <sys/kinfo.h>
59 int swapmode(int *retavail, int *retfree);
61 static int namelength;
63 static int show_fullcmd;
68 * needs to be a global symbol, so wrapper can be modified accordingly.
70 static int show_threads = 0;
72 /* get_process_info passes back a handle. This is what it looks like: */
75 struct kinfo_proc **next_proc; /* points to next valid proc pointer */
76 int remaining; /* number of pointers remaining */
79 /* declarations for load_avg */
82 #define PP(pp, field) ((pp)->kp_ ## field)
83 #define LP(pp, field) ((pp)->kp_lwp.kl_ ## field)
84 #define VP(pp, field) ((pp)->kp_vm_ ## field)
86 /* define what weighted cpu is. */
87 #define weighted_cpu(pct, pp) (PP((pp), swtime) == 0 ? 0.0 : \
88 ((pct) / (1.0 - exp(PP((pp), swtime) * logcpu))))
90 /* what we consider to be process size: */
91 #define PROCSIZE(pp) (VP((pp), map_size) / 1024)
94 * These definitions control the format of the per-process area
97 static char smp_header[] =
98 " PID %-*.*s NICE SIZE PRES STATE CPU TIME CTIME CPU COMMAND";
100 #define smp_Proc_format \
101 "%5d %-*.*s %3d%7s %6s %7.7s %2d %6s %7s %5.2f%% %.*s"
103 static char up_header[] =
104 " PID %-*.*s NICE SIZE PRES STATE TIME CTIME CPU COMMAND";
106 #define up_Proc_format \
107 "%5d %-*.*s %3d%7s %6s %7.7s%.0d %7s %7s %5.2f%% %.*s"
110 /* process state names for the "STATE" column of the display */
112 * the extra nulls in the string "run" are for adding a slash and the
113 * processor number when needed
116 const char *state_abbrev[] = {
117 "", "RUN\0\0\0", "STOP", "SLEEP",
123 /* values that we stash away in _init and use in later routines */
125 static double logcpu;
130 /* these are for calculating cpu state percentages */
132 static struct kinfo_cputime *cp_time, *cp_old;
134 /* these are for detailing the process states */
136 int process_states[6];
137 char *procstatenames[] = {
138 " running, ", " idle, ", " active, ", " stopped, ", " zombie, ",
142 /* these are for detailing the cpu states */
145 char *cpustatenames[CPU_STATES + 1] = {
146 "user", "nice", "system", "interrupt", "idle", NULL
149 /* these are for detailing the memory statistics */
151 long memory_stats[7];
152 char *memorynames[] = {
153 "K Active, ", "K Inact, ", "K Wired, ", "K Cache, ", "K Buf, ", "K Free",
158 char *swapnames[] = {
160 "K Total, ", "K Used, ", "K Free, ", "% Inuse, ", "K In, ", "K Out",
165 /* these are for keeping track of the proc array */
168 static int onproc = -1;
170 static struct kinfo_proc *pbase;
171 static struct kinfo_proc **pref;
173 /* these are for getting the memory statistics */
175 static int pageshift; /* log base 2 of the pagesize */
177 /* define pagetok in terms of pageshift */
179 #define pagetok(size) ((size) << pageshift)
181 /* sorting orders. first is default */
182 char *ordernames[] = {
183 "cpu", "size", "res", "time", "pri", "thr", "pid", "ctime", "pres", NULL
186 /* compare routines */
187 int proc_compare (struct kinfo_proc **, struct kinfo_proc **);
188 int compare_size (struct kinfo_proc **, struct kinfo_proc **);
189 int compare_res (struct kinfo_proc **, struct kinfo_proc **);
190 int compare_time (struct kinfo_proc **, struct kinfo_proc **);
191 int compare_ctime (struct kinfo_proc **, struct kinfo_proc **);
192 int compare_prio(struct kinfo_proc **, struct kinfo_proc **);
193 int compare_thr (struct kinfo_proc **, struct kinfo_proc **);
194 int compare_pid (struct kinfo_proc **, struct kinfo_proc **);
195 int compare_pres(struct kinfo_proc **, struct kinfo_proc **);
197 int (*proc_compares[]) (struct kinfo_proc **,struct kinfo_proc **) = {
211 cputime_percentages(int out[CPU_STATES], struct kinfo_cputime *new,
212 struct kinfo_cputime *old)
214 struct kinfo_cputime diffs;
215 uint64_t total_change, half_total;
220 diffs.cp_user = new->cp_user - old->cp_user;
221 diffs.cp_nice = new->cp_nice - old->cp_nice;
222 diffs.cp_sys = new->cp_sys - old->cp_sys;
223 diffs.cp_intr = new->cp_intr - old->cp_intr;
224 diffs.cp_idle = new->cp_idle - old->cp_idle;
225 total_change = diffs.cp_user + diffs.cp_nice + diffs.cp_sys +
226 diffs.cp_intr + diffs.cp_idle;
227 old->cp_user = new->cp_user;
228 old->cp_nice = new->cp_nice;
229 old->cp_sys = new->cp_sys;
230 old->cp_intr = new->cp_intr;
231 old->cp_idle = new->cp_idle;
233 /* avoid divide by zero potential */
234 if (total_change == 0)
237 /* calculate percentages based on overall change, rounding up */
238 half_total = total_change >> 1;
240 out[0] = ((diffs.cp_user * 1000LL + half_total) / total_change);
241 out[1] = ((diffs.cp_nice * 1000LL + half_total) / total_change);
242 out[2] = ((diffs.cp_sys * 1000LL + half_total) / total_change);
243 out[3] = ((diffs.cp_intr * 1000LL + half_total) / total_change);
244 out[4] = ((diffs.cp_idle * 1000LL + half_total) / total_change);
248 machine_init(struct statics *statics)
253 struct timeval boottime;
256 if (kinfo_get_cpus(&n_cpus))
257 err(1, "kinfo_get_cpus failed");
260 modelen = sizeof(boottime);
261 if (sysctlbyname("kern.boottime", &boottime, &modelen, NULL, 0) == -1) {
262 /* we have no boottime to report */
263 boottime.tv_sec = -1;
265 modelen = sizeof(smpmode);
266 if ((sysctlbyname("machdep.smp_active", &smpmode, &modelen, NULL, 0) < 0 &&
267 sysctlbyname("smp.smp_active", &smpmode, &modelen, NULL, 0) < 0) ||
268 modelen != sizeof(smpmode))
271 while ((pw = getpwent()) != NULL) {
272 if ((int)strlen(pw->pw_name) > namelength)
273 namelength = strlen(pw->pw_name);
277 if (smpmode && namelength > 13)
279 else if (namelength > 15)
282 if ((kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL)
285 if (kinfo_get_sched_ccpu(&ccpu)) {
286 fprintf(stderr, "top: kinfo_get_sched_ccpu failed\n");
289 /* this is used in calculating WCPU -- calculate it ahead of time */
290 logcpu = log(loaddouble(ccpu));
297 * get the page size with "getpagesize" and calculate pageshift from
300 pagesize = getpagesize();
302 while (pagesize > 1) {
307 /* we only need the amount of log(2)1024 for our conversion */
308 pageshift -= LOG1024;
310 /* fill in the statics information */
311 statics->procstate_names = procstatenames;
312 statics->cpustate_names = cpustatenames;
313 statics->memory_names = memorynames;
314 statics->boottime = boottime.tv_sec;
315 statics->swap_names = swapnames;
316 statics->order_names = ordernames;
317 /* we need kvm descriptor in order to show full commands */
318 statics->flags.fullcmds = kd != NULL;
325 format_header(char *uname_field)
327 static char Header[128];
329 snprintf(Header, sizeof(Header), smpmode ? smp_header : up_header,
330 namelength, namelength, uname_field);
332 if (screen_width <= 79)
335 cmdlength = screen_width;
337 cmdlength = cmdlength - strlen(Header) + 6;
342 static int swappgsin = -1;
343 static int swappgsout = -1;
344 extern struct timeval timeout;
347 get_system_info(struct system_info *si)
352 if (cpu_states == NULL) {
353 cpu_states = malloc(sizeof(*cpu_states) * CPU_STATES * n_cpus);
354 if (cpu_states == NULL)
356 bzero(cpu_states, sizeof(*cpu_states) * CPU_STATES * n_cpus);
358 if (cp_time == NULL) {
359 cp_time = malloc(2 * n_cpus * sizeof(cp_time[0]));
362 cp_old = cp_time + n_cpus;
363 len = n_cpus * sizeof(cp_old[0]);
365 if (sysctlbyname("kern.cputime", cp_old, &len, NULL, 0))
366 err(1, "kern.cputime");
368 len = n_cpus * sizeof(cp_time[0]);
370 if (sysctlbyname("kern.cputime", cp_time, &len, NULL, 0))
371 err(1, "kern.cputime");
373 getloadavg(si->load_avg, 3);
377 /* convert cp_time counts to percentages */
378 for (cpu = 0; cpu < n_cpus; ++cpu) {
379 cputime_percentages(cpu_states + cpu * CPU_STATES,
380 &cp_time[cpu], &cp_old[cpu]);
383 /* sum memory & swap statistics */
387 size_t vms_size = sizeof(vms);
388 size_t vmm_size = sizeof(vmm);
389 static unsigned int swap_delay = 0;
390 static int swapavail = 0;
391 static int swapfree = 0;
392 static long bufspace = 0;
394 if (sysctlbyname("vm.vmstats", &vms, &vms_size, NULL, 0))
395 err(1, "sysctlbyname: vm.vmstats");
397 if (sysctlbyname("vm.vmmeter", &vmm, &vmm_size, NULL, 0))
398 err(1, "sysctlbyname: vm.vmmeter");
400 if (kinfo_get_vfs_bufspace(&bufspace))
401 err(1, "kinfo_get_vfs_bufspace");
403 /* convert memory stats to Kbytes */
404 memory_stats[0] = pagetok(vms.v_active_count);
405 memory_stats[1] = pagetok(vms.v_inactive_count);
406 memory_stats[2] = pagetok(vms.v_wire_count);
407 memory_stats[3] = pagetok(vms.v_cache_count);
408 memory_stats[4] = bufspace / 1024;
409 memory_stats[5] = pagetok(vms.v_free_count);
410 memory_stats[6] = -1;
417 /* compute differences between old and new swap statistic */
419 swap_stats[4] = pagetok(((vmm.v_swappgsin - swappgsin)));
420 swap_stats[5] = pagetok(((vmm.v_swappgsout - swappgsout)));
423 swappgsin = vmm.v_swappgsin;
424 swappgsout = vmm.v_swappgsout;
426 /* call CPU heavy swapmode() only for changes */
427 if (swap_stats[4] > 0 || swap_stats[5] > 0 || swap_delay == 0) {
428 swap_stats[3] = swapmode(&swapavail, &swapfree);
429 swap_stats[0] = swapavail;
430 swap_stats[1] = swapavail - swapfree;
431 swap_stats[2] = swapfree;
437 /* set arrays and strings */
438 si->cpustates = cpu_states;
439 si->memory = memory_stats;
440 si->swap = swap_stats;
444 si->last_pid = lastpid;
451 static struct handle handle;
454 get_process_info(struct system_info *si, struct process_select *sel,
460 struct kinfo_proc **prefp;
461 struct kinfo_proc *pp;
463 /* these are copied out of sel for speed */
469 pbase = kvm_getprocs(kd, KERN_PROC_ALL, 0, &nproc);
471 pref = (struct kinfo_proc **)realloc(pref, sizeof(struct kinfo_proc *)
473 if (pref == NULL || pbase == NULL) {
474 (void)fprintf(stderr, "top: Out of memory.\n");
477 /* get a pointer to the states summary array */
478 si->procstates = process_states;
480 /* set up flags which define what we are going to select */
481 show_idle = sel->idle;
482 show_system = sel->system;
483 show_uid = sel->uid != -1;
484 show_fullcmd = sel->fullcmd;
486 /* count up process states and get pointers to interesting procs */
489 memset((char *)process_states, 0, sizeof(process_states));
491 for (pp = pbase, i = 0; i < nproc; pp++, i++) {
493 * Place pointers to each valid proc structure in pref[].
494 * Process slots that are actually in use have a non-zero
495 * status field. Processes with P_SYSTEM set are system
496 * processes---these get ignored unless show_sysprocs is set.
498 if ((show_threads && (LP(pp, pid) == -1)) ||
499 (show_system || ((PP(pp, flags) & P_SYSTEM) == 0))) {
501 if (LP(pp, stat) == LSRUN)
503 process_states[PP(pp, stat)]++;
504 if ((show_threads && (LP(pp, pid) == -1)) ||
505 (show_idle || (LP(pp, pctcpu) != 0) ||
506 (LP(pp, stat) == LSRUN)) &&
507 (!show_uid || PP(pp, ruid) == (uid_t) sel->uid)) {
514 qsort((char *)pref, active_procs, sizeof(struct kinfo_proc *),
515 (int (*)(const void *, const void *))proc_compares[compare_index]);
517 /* remember active and total counts */
518 si->p_total = total_procs;
519 si->p_active = pref_len = active_procs;
521 /* pass back a handle */
522 handle.next_proc = pref;
523 handle.remaining = active_procs;
524 return ((caddr_t) & handle);
527 char fmt[MAX_COLS]; /* static area where result is built */
530 format_next_process(caddr_t xhandle, char *(*get_userid) (int))
532 struct kinfo_proc *pp;
542 char cputime_fmt[10], ccputime_fmt[10];
544 /* find and remember the next proc structure */
545 hp = (struct handle *)xhandle;
546 pp = *(hp->next_proc++);
549 /* get the process's command name */
551 if ((comm_full = kvm_getargv(kd, pp, 0)) == NULL) {
560 * Convert the process's runtime from microseconds to seconds. This
561 * time includes the interrupt time to be in compliance with ps output.
563 cputime = (LP(pp, uticks) + LP(pp, sticks) + LP(pp, iticks)) / 1000000;
564 ccputime = cputime + PP(pp, cru).ru_stime.tv_sec + PP(pp, cru).ru_utime.tv_sec;
565 format_time(cputime, cputime_fmt, sizeof(cputime_fmt));
566 format_time(ccputime, ccputime_fmt, sizeof(ccputime_fmt));
568 /* calculate the base for cpu percentages */
569 pct = pctdouble(LP(pp, pctcpu));
571 /* generate "STATE" field */
572 switch (state = LP(pp, stat)) {
574 if (smpmode && LP(pp, tdflags) & TDF_RUNNING)
575 sprintf(status, "CPU%d", LP(pp, cpuid));
577 strcpy(status, "RUN");
580 if (LP(pp, wmesg) != NULL) {
581 sprintf(status, "%.6s", LP(pp, wmesg));
588 (unsigned)state < sizeof(state_abbrev) / sizeof(*state_abbrev))
589 sprintf(status, "%.6s", state_abbrev[(unsigned char)state]);
591 sprintf(status, "?%5d", state);
595 if (PP(pp, stat) == SZOMB)
596 strcpy(status, "ZOMB");
599 * idle time 0 - 31 -> nice value +21 - +52 normal time -> nice
600 * value -20 - +20 real time 0 - 31 -> nice value -52 - -21 thread
601 * 0 - 31 -> nice value -53 -
603 switch (LP(pp, rtprio.type)) {
604 case RTP_PRIO_REALTIME:
605 xnice = PRIO_MIN - 1 - RTP_PRIO_MAX + LP(pp, rtprio.prio);
608 xnice = PRIO_MAX + 1 + LP(pp, rtprio.prio);
610 case RTP_PRIO_THREAD:
611 xnice = PRIO_MIN - 1 - RTP_PRIO_MAX - LP(pp, rtprio.prio);
614 xnice = PP(pp, nice);
618 /* format this entry */
619 snprintf(fmt, sizeof(fmt),
620 smpmode ? smp_Proc_format : up_Proc_format,
622 namelength, namelength,
623 get_userid(PP(pp, ruid)),
625 format_k(PROCSIZE(pp)),
626 format_k(pagetok(VP(pp, prssize))),
628 (int)(smpmode ? LP(pp, cpuid) : 0),
633 show_fullcmd ? *comm_full : comm);
635 /* return the result */
639 /* comparison routines for qsort */
642 * proc_compare - comparison function for "qsort"
643 * Compares the resource consumption of two processes using five
644 * distinct keys. The keys (in descending order of importance) are:
645 * percent cpu, cpu ticks, state, resident set size, total virtual
646 * memory usage. The process states are ordered as follows (from least
647 * to most important): WAIT, zombie, sleep, stop, start, run. The
648 * array declaration below maps a process state index into a number
649 * that reflects this ordering.
652 static unsigned char sorted_state[] =
656 1, /* ABANDONED (WAIT) */
664 #define ORDERKEY_PCTCPU \
665 if (lresult = (long) LP(p2, pctcpu) - (long) LP(p1, pctcpu), \
666 (result = lresult > 0 ? 1 : lresult < 0 ? -1 : 0) == 0)
668 #define CPTICKS(p) (LP(p, uticks) + LP(p, sticks) + LP(p, iticks))
670 #define ORDERKEY_CPTICKS \
671 if ((result = CPTICKS(p2) > CPTICKS(p1) ? 1 : \
672 CPTICKS(p2) < CPTICKS(p1) ? -1 : 0) == 0)
674 #define CTIME(p) (((LP(p, uticks) + LP(p, sticks) + LP(p, iticks))/1000000) + \
675 PP(p, cru).ru_stime.tv_sec + PP(p, cru).ru_utime.tv_sec)
677 #define ORDERKEY_CTIME \
678 if ((result = CTIME(p2) > CTIME(p1) ? 1 : \
679 CTIME(p2) < CTIME(p1) ? -1 : 0) == 0)
681 #define ORDERKEY_STATE \
682 if ((result = sorted_state[(unsigned char) PP(p2, stat)] - \
683 sorted_state[(unsigned char) PP(p1, stat)]) == 0)
685 #define ORDERKEY_PRIO \
686 if ((result = LP(p2, prio) - LP(p1, prio)) == 0)
688 #define ORDERKEY_KTHREADS \
689 if ((result = (LP(p1, pid) == 0) - (LP(p2, pid) == 0)) == 0)
691 #define ORDERKEY_KTHREADS_PRIO \
692 if ((result = LP(p2, tdprio) - LP(p1, tdprio)) == 0)
694 #define ORDERKEY_RSSIZE \
695 if ((result = VP(p2, rssize) - VP(p1, rssize)) == 0)
697 #define ORDERKEY_MEM \
698 if ( (result = PROCSIZE(p2) - PROCSIZE(p1)) == 0 )
700 #define ORDERKEY_PID \
701 if ( (result = PP(p1, pid) - PP(p2, pid)) == 0)
703 #define ORDERKEY_PRSSIZE \
704 if((result = VP(p2, prssize) - VP(p1, prssize)) == 0)
706 /* compare_cpu - the comparison function for sorting by cpu percentage */
709 proc_compare(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
711 struct kinfo_proc *p1;
712 struct kinfo_proc *p2;
716 /* remove one level of indirection */
717 p1 = *(struct kinfo_proc **) pp1;
718 p2 = *(struct kinfo_proc **) pp2;
731 /* compare_size - the comparison function for sorting by total memory usage */
734 compare_size(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
736 struct kinfo_proc *p1;
737 struct kinfo_proc *p2;
741 /* remove one level of indirection */
742 p1 = *(struct kinfo_proc **) pp1;
743 p2 = *(struct kinfo_proc **) pp2;
756 /* compare_res - the comparison function for sorting by resident set size */
759 compare_res(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
761 struct kinfo_proc *p1;
762 struct kinfo_proc *p2;
766 /* remove one level of indirection */
767 p1 = *(struct kinfo_proc **) pp1;
768 p2 = *(struct kinfo_proc **) pp2;
781 /* compare_pres - the comparison function for sorting by proportional resident set size */
784 compare_pres(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
786 struct kinfo_proc *p1;
787 struct kinfo_proc *p2;
791 /* remove one level of indirection */
792 p1 = *(struct kinfo_proc **) pp1;
793 p2 = *(struct kinfo_proc **) pp2;
807 /* compare_time - the comparison function for sorting by total cpu time */
810 compare_time(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
812 struct kinfo_proc *p1;
813 struct kinfo_proc *p2;
817 /* remove one level of indirection */
818 p1 = *(struct kinfo_proc **) pp1;
819 p2 = *(struct kinfo_proc **) pp2;
824 ORDERKEY_KTHREADS_PRIO
835 compare_ctime(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
837 struct kinfo_proc *p1;
838 struct kinfo_proc *p2;
842 /* remove one level of indirection */
843 p1 = *(struct kinfo_proc **) pp1;
844 p2 = *(struct kinfo_proc **) pp2;
849 ORDERKEY_KTHREADS_PRIO
859 /* compare_prio - the comparison function for sorting by cpu percentage */
862 compare_prio(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
864 struct kinfo_proc *p1;
865 struct kinfo_proc *p2;
869 /* remove one level of indirection */
870 p1 = *(struct kinfo_proc **) pp1;
871 p2 = *(struct kinfo_proc **) pp2;
874 ORDERKEY_KTHREADS_PRIO
887 compare_thr(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
889 struct kinfo_proc *p1;
890 struct kinfo_proc *p2;
894 /* remove one level of indirection */
895 p1 = *(struct kinfo_proc **)pp1;
896 p2 = *(struct kinfo_proc **)pp2;
899 ORDERKEY_KTHREADS_PRIO
910 /* compare_pid - the comparison function for sorting by process id */
913 compare_pid(struct kinfo_proc **pp1, struct kinfo_proc **pp2)
915 struct kinfo_proc *p1;
916 struct kinfo_proc *p2;
919 /* remove one level of indirection */
920 p1 = *(struct kinfo_proc **) pp1;
921 p2 = *(struct kinfo_proc **) pp2;
930 * proc_owner(pid) - returns the uid that owns process "pid", or -1 if
931 * the process does not exist.
932 * It is EXTREMLY IMPORTANT that this function work correctly.
933 * If top runs setuid root (as in SVR4), then this function
934 * is the only thing that stands in the way of a serious
935 * security problem. It validates requests for the "kill"
936 * and "renice" commands.
943 struct kinfo_proc **prefp;
944 struct kinfo_proc *pp;
948 while (--xcnt >= 0) {
950 if (PP(pp, pid) == (pid_t) pid) {
951 return ((int)PP(pp, ruid));
959 * swapmode is based on a program called swapinfo written
960 * by Kevin Lahey <kml@rokkaku.atl.ga.us>.
963 swapmode(int *retavail, int *retfree)
966 int pagesize = getpagesize();
967 struct kvm_swap swapary[1];
972 #define CONVERT(v) ((quad_t)(v) * pagesize / 1024)
974 n = kvm_getswapinfo(kd, swapary, 1, 0);
975 if (n < 0 || swapary[0].ksw_total == 0)
978 *retavail = CONVERT(swapary[0].ksw_total);
979 *retfree = CONVERT(swapary[0].ksw_total - swapary[0].ksw_used);
981 n = (int)((double)swapary[0].ksw_used * 100.0 /
982 (double)swapary[0].ksw_total);