Deleted Added
full compact
linprocfs.c (205695) linprocfs.c (206081)
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 205695 2010-03-26 14:36:16Z netchild $");
45__FBSDID("$FreeBSD: head/sys/compat/linprocfs/linprocfs.c 206081 2010-04-02 06:50:28Z 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#define T2J(x) (((x) * 100UL) / (stathz ? stathz : hz)) /* ticks to jiffies */
113#define T2J(x) ((long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to jiffies */
114#define T2CS(x) ((unsigned long)(((x) * 100ULL) / (stathz ? stathz : hz))) /* ticks to centiseconds */
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 */
115#define T2S(x) ((x) / (stathz ? stathz : hz)) /* ticks to seconds */
116#define B2K(x) ((x) >> 10) /* bytes to kbytes */
117#define B2P(x) ((x) >> PAGE_SHIFT) /* bytes to pages */
118#define P2B(x) ((x) << PAGE_SHIFT) /* pages to bytes */
119#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* pages to kbytes */
120#define TV2J(x) ((x)->tv_sec * 100UL + (x)->tv_usec / 10000)
119
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.

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

500static int
501linprocfs_douptime(PFS_FILL_ARGS)
502{
503 long cp_time[CPUSTATES];
504 struct timeval tv;
505
506 getmicrouptime(&tv);
507 read_cpu_time(cp_time);
121
122/**
123 * @brief Mapping of ki_stat in struct kinfo_proc to the linux state
124 *
125 * The linux procfs state field displays one of the characters RSDZTW to
126 * denote running, sleeping in an interruptible wait, waiting in an
127 * uninterruptible disk sleep, a zombie process, process is being traced
128 * or stopped, or process is paging respectively.

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

502static int
503linprocfs_douptime(PFS_FILL_ARGS)
504{
505 long cp_time[CPUSTATES];
506 struct timeval tv;
507
508 getmicrouptime(&tv);
509 read_cpu_time(cp_time);
508 sbuf_printf(sb, "%lld.%02ld %ld.%02ld\n",
510 sbuf_printf(sb, "%lld.%02ld %ld.%02lu\n",
509 (long long)tv.tv_sec, tv.tv_usec / 10000,
511 (long long)tv.tv_sec, tv.tv_usec / 10000,
510 T2S(cp_time[CP_IDLE]), T2J(cp_time[CP_IDLE]) % 100);
512 T2S(cp_time[CP_IDLE] / mp_ncpus),
513 T2CS(cp_time[CP_IDLE] / mp_ncpus) % 100);
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;
514 return (0);
515}
516
517/*
518 * Get OS build date
519 */
520static void
521linprocfs_osbuild(struct thread *td, struct sbuf *sb)

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

611 * Filler function for proc/pid/stat
612 */
613static int
614linprocfs_doprocstat(PFS_FILL_ARGS)
615{
616 struct kinfo_proc kp;
617 char state;
618 static int ratelimit = 0;
619 vm_offset_t startcode, startdata;
616
617 PROC_LOCK(p);
618 fill_kinfo_proc(p, &kp);
620
621 PROC_LOCK(p);
622 fill_kinfo_proc(p, &kp);
623 if (p->p_vmspace) {
624 startcode = (vm_offset_t)p->p_vmspace->vm_taddr;
625 startdata = (vm_offset_t)p->p_vmspace->vm_daddr;
626 } else {
627 startcode = 0;
628 startdata = 0;
629 };
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);
630 sbuf_printf(sb, "%d", p->p_pid);
631#define PS_ADD(name, fmt, arg) sbuf_printf(sb, " " fmt, arg)
632 PS_ADD("comm", "(%s)", p->p_comm);
633 if (kp.ki_stat > sizeof(linux_state)) {
634 state = 'R';
635
636 if (ratelimit == 0) {
637 printf("linprocfs: don't know how to handle unknown FreeBSD state %d/%zd, mapping to R\n",
638 kp.ki_stat, sizeof(linux_state));
639 ++ratelimit;
640 }
641 } else
642 state = linux_state[kp.ki_stat - 1];
643 PS_ADD("state", "%c", state);
644 PS_ADD("ppid", "%d", p->p_pptr ? p->p_pptr->p_pid : 0);
645 PS_ADD("pgrp", "%d", p->p_pgid);
646 PS_ADD("session", "%d", p->p_session->s_sid);
647 PROC_UNLOCK(p);
637 PS_ADD("tty", "%d", 0); /* XXX */
648 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);
649 PS_ADD("tpgid", "%d", kp.ki_tpgid);
650 PS_ADD("flags", "%u", 0); /* XXX */
651 PS_ADD("minflt", "%lu", kp.ki_rusage.ru_minflt);
652 PS_ADD("cminflt", "%lu", kp.ki_rusage_ch.ru_minflt);
653 PS_ADD("majflt", "%lu", kp.ki_rusage.ru_majflt);
654 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)));
655 PS_ADD("utime", "%ld", TV2J(&kp.ki_rusage.ru_utime));
656 PS_ADD("stime", "%ld", TV2J(&kp.ki_rusage.ru_stime));
657 PS_ADD("cutime", "%ld", TV2J(&kp.ki_rusage_ch.ru_utime));
658 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 */
659 PS_ADD("priority", "%d", kp.ki_pri.pri_user);
660 PS_ADD("nice", "%d", kp.ki_nice); /* 19 (nicest) to -19 */
661 PS_ADD("0", "%d", 0); /* removed field */
662 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)));
663 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);
664 PS_ADD("vsize", "%ju", P2K((uintmax_t)kp.ki_size));
665 PS_ADD("rss", "%ju", (uintmax_t)kp.ki_rssize);
666 PS_ADD("rlim", "%lu", kp.ki_rusage.ru_maxrss);
659 PS_ADD("startcode", "%u", (unsigned)0);
660 PS_ADD("endcode", "%u", 0); /* XXX */
667 PS_ADD("startcode", "%ju", (uintmax_t)startcode);
668 PS_ADD("endcode", "%ju", (uintmax_t)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 */
669 PS_ADD("startstack", "%u", 0); /* XXX */
670 PS_ADD("kstkesp", "%u", 0); /* XXX */
671 PS_ADD("kstkeip", "%u", 0); /* XXX */
672 PS_ADD("signal", "%u", 0); /* XXX */
673 PS_ADD("blocked", "%u", 0); /* XXX */
674 PS_ADD("sigignore", "%u", 0); /* XXX */
675 PS_ADD("sigcatch", "%u", 0); /* XXX */
676 PS_ADD("wchan", "%u", 0); /* XXX */

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

803 * it has much meaning anyway), I believe it's good enough.
804 *
805 * The same code that could (I think) accurately compute VmLib
806 * could also compute VmLck, but I don't really care enough to
807 * implement it. Submissions are welcome.
808 */
809 sbuf_printf(sb, "VmSize:\t%8ju kB\n", B2K((uintmax_t)kp.ki_size));
810 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));
811 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 ---
812 sbuf_printf(sb, "VmData:\t%8ju kB\n", P2K((uintmax_t)kp.ki_dsize));
813 sbuf_printf(sb, "VmStk:\t%8ju kB\n", P2K((uintmax_t)kp.ki_ssize));
814 sbuf_printf(sb, "VmExe:\t%8ju kB\n", P2K((uintmax_t)kp.ki_tsize));
815 lsize = B2P(kp.ki_size) - kp.ki_dsize -
816 kp.ki_ssize - kp.ki_tsize - 1;
817 sbuf_printf(sb, "VmLib:\t%8ju kB\n", P2K((uintmax_t)lsize));
818
819 /*

--- 583 unchanged lines hidden ---