linprocfs.c (205592) | linprocfs.c (205683) |
---|---|
1/*- 2 * Copyright (c) 2000 Dag-Erling Co��dan Sm��rgrav 3 * Copyright (c) 1999 Pierre Beyssac 4 * Copyright (c) 1993 Jan-Simon Pendry 5 * Copyright (c) 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 28 unchanged lines hidden (view full) --- 37 * SUCH DAMAGE. 38 * 39 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 40 */ 41 42#include "opt_compat.h" 43 44#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000 Dag-Erling Co��dan Sm��rgrav 3 * Copyright (c) 1999 Pierre Beyssac 4 * Copyright (c) 1993 Jan-Simon Pendry 5 * Copyright (c) 1993 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by --- 28 unchanged lines hidden (view full) --- 37 * SUCH DAMAGE. 38 * 39 * @(#)procfs_status.c 8.4 (Berkeley) 6/15/94 40 */ 41 42#include "opt_compat.h" 43 44#include <sys/cdefs.h> |
45__FBSDID("$FreeBSD: head/sys/compat/linprocfs/linprocfs.c 205592 2010-03-24 14:20:37Z jhb $"); | 45__FBSDID("$FreeBSD: head/sys/compat/linprocfs/linprocfs.c 205683 2010-03-26 11:43:15Z netchild $"); |
46 47#include <sys/param.h> 48#include <sys/queue.h> 49#include <sys/blist.h> 50#include <sys/conf.h> 51#include <sys/exec.h> 52#include <sys/fcntl.h> 53#include <sys/filedesc.h> --- 51 unchanged lines hidden (view full) --- 105#include <compat/linux/linux_mib.h> 106#include <compat/linux/linux_util.h> 107#include <fs/pseudofs/pseudofs.h> 108#include <fs/procfs/procfs.h> 109 110/* 111 * Various conversion macros 112 */ | 46 47#include <sys/param.h> 48#include <sys/queue.h> 49#include <sys/blist.h> 50#include <sys/conf.h> 51#include <sys/exec.h> 52#include <sys/fcntl.h> 53#include <sys/filedesc.h> --- 51 unchanged lines hidden (view full) --- 105#include <compat/linux/linux_mib.h> 106#include <compat/linux/linux_util.h> 107#include <fs/pseudofs/pseudofs.h> 108#include <fs/procfs/procfs.h> 109 110/* 111 * Various conversion macros 112 */ |
113 114/* The LINUX_USER_HZ is assumed 100 for now */ 115 116#if defined(__i386__) && defined(__GNUCLIKE_ASM) 117/* we need intermediate result as 64 bit, otherwise it overflows too early */ 118#define DO64_MULDIV(v,m,d) \ 119({ \ 120 unsigned long rv0; \ 121 unsigned long rv1; \ 122 __asm__ __volatile__( \ 123 "mull %1\n\t" \ 124 "divl %2\n\t" \ 125 :"=a" (rv0), "=d" (rv1) \ 126 :"r" (d), "0" (v), "1" (m) \ 127 :"cc" ); \ 128 rv0; \ 129}) 130 131#define T2J(x) DO64_MULDIV((x), 100UL, (stathz ? stathz : hz)) /* ticks to jiffies */ 132#else |
|
113#define T2J(x) (((x) * 100UL) / (stathz ? stathz : hz)) /* ticks to jiffies */ | 133#define T2J(x) (((x) * 100UL) / (stathz ? stathz : hz)) /* ticks to jiffies */ |
134#endif |
|
114#define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */ 115#define B2K(x) ((x) >> 10) /* bytes to kbytes */ 116#define B2P(x) ((x) >> PAGE_SHIFT) /* bytes to pages */ 117#define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */ 118#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ 119 | 135#define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */ 136#define B2K(x) ((x) >> 10) /* bytes to kbytes */ 137#define B2P(x) ((x) >> PAGE_SHIFT) /* bytes to pages */ 138#define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */ 139#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */ 140 |
141#define TV2J(x) (((x)->tv_sec) * 100UL + ((x)->tv_usec) / 10000) 142 |
|
120/** 121 * @brief Mapping of ki_stat in struct kinfo_proc to the linux state 122 * 123 * The linux procfs state field displays one of the characters RSDZTW to 124 * denote running, sleeping in an interruptible wait, waiting in an 125 * uninterruptible disk sleep, a zombie process, process is being traced 126 * or stopped, or process is paging respectively. 127 * --- 369 unchanged lines hidden (view full) --- 497/* 498 * Filler function for proc/uptime 499 */ 500static int 501linprocfs_douptime(PFS_FILL_ARGS) 502{ 503 long cp_time[CPUSTATES]; 504 struct timeval tv; | 143/** 144 * @brief Mapping of ki_stat in struct kinfo_proc to the linux state 145 * 146 * The linux procfs state field displays one of the characters RSDZTW to 147 * denote running, sleeping in an interruptible wait, waiting in an 148 * uninterruptible disk sleep, a zombie process, process is being traced 149 * or stopped, or process is paging respectively. 150 * --- 369 unchanged lines hidden (view full) --- 520/* 521 * Filler function for proc/uptime 522 */ 523static int 524linprocfs_douptime(PFS_FILL_ARGS) 525{ 526 long cp_time[CPUSTATES]; 527 struct timeval tv; |
528 int cnt, i; |
|
505 506 getmicrouptime(&tv); 507 read_cpu_time(cp_time); | 529 530 getmicrouptime(&tv); 531 read_cpu_time(cp_time); |
508 sbuf_printf(sb, "%lld.%02ld %ld.%02ld\n", | 532 533 for (cnt = 0, i = 0; i <= mp_maxid; ++i) 534 if (!(CPU_ABSENT(i))) 535 cnt++; 536 537 if (!cnt) 538 cnt = 1; 539 540 i = ((cp_time[CP_IDLE])/cnt) % (stathz ? stathz : hz); 541 i = (i * 100) / (stathz ? stathz : hz); 542 543 sbuf_printf(sb, "%lld.%02ld %ld.%02d\n", |
509 (long long)tv.tv_sec, tv.tv_usec / 10000, | 544 (long long)tv.tv_sec, tv.tv_usec / 10000, |
510 T2S(cp_time[CP_IDLE]), T2J(cp_time[CP_IDLE]) % 100); | 545 T2S((cp_time[CP_IDLE]/cnt)), i); |
511 return (0); 512} 513 514/* 515 * Get OS build date 516 */ 517static void 518linprocfs_osbuild(struct thread *td, struct sbuf *sb) --- 89 unchanged lines hidden (view full) --- 608 * Filler function for proc/pid/stat 609 */ 610static int 611linprocfs_doprocstat(PFS_FILL_ARGS) 612{ 613 struct kinfo_proc kp; 614 char state; 615 static int ratelimit = 0; | 546 return (0); 547} 548 549/* 550 * Get OS build date 551 */ 552static void 553linprocfs_osbuild(struct thread *td, struct sbuf *sb) --- 89 unchanged lines hidden (view full) --- 643 * Filler function for proc/pid/stat 644 */ 645static int 646linprocfs_doprocstat(PFS_FILL_ARGS) 647{ 648 struct kinfo_proc kp; 649 char state; 650 static int ratelimit = 0; |
651 unsigned long startcode, startdata; |
|
616 617 PROC_LOCK(p); 618 fill_kinfo_proc(p, &kp); | 652 653 PROC_LOCK(p); 654 fill_kinfo_proc(p, &kp); |
655 if (p->p_vmspace) { 656 startcode = (unsigned long) p->p_vmspace->vm_taddr; 657 startdata = (unsigned long) p->p_vmspace->vm_daddr; 658 } else { 659 startcode = 0; 660 startdata = 0; 661 }; |
|
619 sbuf_printf(sb, "%d", p->p_pid); 620#define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg) 621 PS_ADD("comm", "(%s)", p->p_comm); 622 if (kp.ki_stat > sizeof(linux_state)) { 623 state = 'R'; 624 625 if (ratelimit == 0) { 626 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n", 627 kp.ki_stat, sizeof(linux_state)); 628 ++ratelimit; 629 } 630 } else 631 state = linux_state[kp.ki_stat - 1]; 632 PS_ADD("state", "%c", state); 633 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0); 634 PS_ADD("pgrp", "%d", p->p_pgid); 635 PS_ADD("session", "%d", p->p_session->s_sid); 636 PROC_UNLOCK(p); | 662 sbuf_printf(sb, "%d", p->p_pid); 663#define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg) 664 PS_ADD("comm", "(%s)", p->p_comm); 665 if (kp.ki_stat > sizeof(linux_state)) { 666 state = 'R'; 667 668 if (ratelimit == 0) { 669 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n", 670 kp.ki_stat, sizeof(linux_state)); 671 ++ratelimit; 672 } 673 } else 674 state = linux_state[kp.ki_stat - 1]; 675 PS_ADD("state", "%c", state); 676 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0); 677 PS_ADD("pgrp", "%d", p->p_pgid); 678 PS_ADD("session", "%d", p->p_session->s_sid); 679 PROC_UNLOCK(p); |
637 PS_ADD("tty", "%d", 0); /* XXX */ | 680 PS_ADD("tty", "%d", kp.ki_tdev); |
638 PS_ADD("tpgid", "%d", kp.ki_tpgid); 639 PS_ADD("flags", "%u", 0); /* XXX */ 640 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt); 641 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt); 642 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt); 643 PS_ADD("cmajflt", "%lu", kp.ki_rusage_ch.ru_majflt); | 681 PS_ADD("tpgid", "%d", kp.ki_tpgid); 682 PS_ADD("flags", "%u", 0); /* XXX */ 683 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt); 684 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt); 685 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt); 686 PS_ADD("cmajflt", "%lu", kp.ki_rusage_ch.ru_majflt); |
644 PS_ADD("utime", "%ld", T2J(tvtohz(&kp.ki_rusage.ru_utime))); 645 PS_ADD("stime", "%ld", T2J(tvtohz(&kp.ki_rusage.ru_stime))); 646 PS_ADD("cutime", "%ld", T2J(tvtohz(&kp.ki_rusage_ch.ru_utime))); 647 PS_ADD("cstime", "%ld", T2J(tvtohz(&kp.ki_rusage_ch.ru_stime))); | 687 PS_ADD("utime", "%ld", TV2J((&kp.ki_rusage.ru_utime))); 688 PS_ADD("stime", "%ld", TV2J((&kp.ki_rusage.ru_stime))); 689 PS_ADD("cutime", "%ld", TV2J((&kp.ki_rusage_ch.ru_utime))); 690 PS_ADD("cstime", "%ld", TV2J((&kp.ki_rusage_ch.ru_stime))); |
648 PS_ADD("priority", "%d", kp.ki_pri.pri_user); 649 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */ 650 PS_ADD("0", "%d", 0); /* removed field */ 651 PS_ADD("itrealvalue", "%d", 0); /* XXX */ | 691 PS_ADD("priority", "%d", kp.ki_pri.pri_user); 692 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */ 693 PS_ADD("0", "%d", 0); /* removed field */ 694 PS_ADD("itrealvalue", "%d", 0); /* XXX */ |
652 /* XXX: starttime is not right, it is the _same_ for _every_ process. 653 It should be the number of jiffies between system boot and process 654 start. */ 655 PS_ADD("starttime", "%lu", T2J(tvtohz(&kp.ki_start))); | 695 PS_ADD("starttime", "%lu", TV2J((&kp.ki_start)) - TV2J((&boottime))); |
656 PS_ADD("vsize", "%ju", P2K((uintmax_t)kp.ki_size)); 657 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize); 658 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss); | 696 PS_ADD("vsize", "%ju", P2K((uintmax_t)kp.ki_size)); 697 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize); 698 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss); |
659 PS_ADD("startcode", "%u", (unsigned)0); 660 PS_ADD("endcode", "%u", 0); /* XXX */ | 699 PS_ADD("startcode", "%lu", startcode); 700 PS_ADD("endcode", "%lu", startdata); |
661 PS_ADD("startstack", "%u", 0); /* XXX */ 662 PS_ADD("kstkesp", "%u", 0); /* XXX */ 663 PS_ADD("kstkeip", "%u", 0); /* XXX */ 664 PS_ADD("signal", "%u", 0); /* XXX */ 665 PS_ADD("blocked", "%u", 0); /* XXX */ 666 PS_ADD("sigignore", "%u", 0); /* XXX */ 667 PS_ADD("sigcatch", "%u", 0); /* XXX */ 668 PS_ADD("wchan", "%u", 0); /* XXX */ --- 126 unchanged lines hidden (view full) --- 795 * it has much meaning anyway), I believe it's good enough. 796 * 797 * The same code that could (I think) accurately compute VmLib 798 * could also compute VmLck, but I don't really care enough to 799 * implement it. Submissions are welcome. 800 */ 801 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size)); 802 sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */ | 701 PS_ADD("startstack", "%u", 0); /* XXX */ 702 PS_ADD("kstkesp", "%u", 0); /* XXX */ 703 PS_ADD("kstkeip", "%u", 0); /* XXX */ 704 PS_ADD("signal", "%u", 0); /* XXX */ 705 PS_ADD("blocked", "%u", 0); /* XXX */ 706 PS_ADD("sigignore", "%u", 0); /* XXX */ 707 PS_ADD("sigcatch", "%u", 0); /* XXX */ 708 PS_ADD("wchan", "%u", 0); /* XXX */ --- 126 unchanged lines hidden (view full) --- 835 * it has much meaning anyway), I believe it's good enough. 836 * 837 * The same code that could (I think) accurately compute VmLib 838 * could also compute VmLck, but I don't really care enough to 839 * implement it. Submissions are welcome. 840 */ 841 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size)); 842 sbuf_printf(sb, "VmLck:\t%8u kB\n", P2K(0)); /* XXX */ |
803 sbuf_printf(sb, "VmRss:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize)); | 843 sbuf_printf(sb, "VmRSS:\t%8ju kB\n", P2K((uintmax_t)kp.ki_rssize)); |
804 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize)); 805 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize)); 806 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize)); 807 lsize = B2P(kp.ki_size) - kp.ki_dsize - 808 kp.ki_ssize - kp.ki_tsize - 1; 809 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize)); 810 811 /* --- 583 unchanged lines hidden --- | 844 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize)); 845 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize)); 846 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize)); 847 lsize = B2P(kp.ki_size) - kp.ki_dsize - 848 kp.ki_ssize - kp.ki_tsize - 1; 849 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize)); 850 851 /* --- 583 unchanged lines hidden --- |