Fixup fromcvs/togit conversion
[minix-pkgsrc.git] / sysutils / libgtop / patches / patch-ab
blobc5dfcf63e0296f51fbdea70f84f7604173948419
1 $NetBSD$
3 --- sysdeps/bsd/proctime.c.orig 2007-04-27 00:27:34.000000000 +0200
4 +++ sysdeps/bsd/proctime.c
5 @@ -40,11 +40,25 @@ static const unsigned long _glibtop_sysd
6  
7  #define tv2sec(tv)     (((guint64) tv.tv_sec * 1000000) + (guint64) tv.tv_usec)
8  
9 +#if defined(__NetBSD__)
10 +static unsigned int clockrate;
11 +static const int mib [] = { CTL_KERN, KERN_CLOCKRATE };
12 +#endif
14  /* Init function. */
16  void
17  _glibtop_init_proc_time_p (glibtop *server)
18  {
19 +#if defined(__NetBSD__)
20 +       struct clockinfo ci;
21 +       size_t length;
22 +       length = sizeof (ci);
23 +       if (sysctl (mib, 2, &ci, &length, NULL, 0) == 0)
24 +               clockrate = ci.hz;
25 +       if (!clockrate)
26 +               clockrate = 1; /* XXX avoid div by 0 later */
27 +#endif
28         server->sysdeps.proc_time = _glibtop_sysdeps_proc_time |
29                 _glibtop_sysdeps_proc_time_user;
30  }
31 @@ -56,7 +70,7 @@ _glibtop_init_proc_time_p (glibtop *serv
32   * system, and interrupt time usage.
33   */
35 -#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__))
36 +#if !(defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__))
38  static void
39  calcru(p, up, sp, ip)
40 @@ -114,13 +128,17 @@ void
41  glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
42                          pid_t pid)
43  {
44 +#if defined (__NetBSD__)
45 +       struct kinfo_proc2 *pinfo;
46 +#else
47         struct kinfo_proc *pinfo;
48 -#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
49 +#if (defined(OpenBSD) && (OpenBSD >= 199912))
50         register struct rusage *rup;
51  #else
52         struct user *u_addr = (struct user *)USRSTACK;
53  #endif
54         struct pstats pstats;
55 +#endif /* NetBSD */
56         int count;
58         glibtop_init_p (server, (1L << GLIBTOP_SYSDEPS_PROC_TIME), 0);
59 @@ -136,7 +154,12 @@ glibtop_get_proc_time_p (glibtop *server
60  #endif
62         /* Get the process information */
63 +#if defined (__NetBSD__)
64 +       pinfo = kvm_getproc2 (server->machine.kd, KERN_PROC_PID, pid,
65 +                             sizeof (*pinfo), &count);
66 +#else
67         pinfo = kvm_getprocs (server->machine.kd, KERN_PROC_PID, pid, &count);
68 +#endif
69         if ((pinfo == NULL) || (count != 1)) {
70                 glibtop_warn_io_r (server, "kvm_getprocs (%d)", pid);
71                 return;
72 @@ -146,14 +169,31 @@ glibtop_get_proc_time_p (glibtop *server
73         buf->rtime = pinfo [0].ki_runtime;
74  #elif (defined __FreeBSD__) && (__FreeBSD_version <= 500013)
75         buf->rtime = pinfo [0].kp_proc.p_runtime;
76 +#elif defined (__NetBSD__)
77 +       buf->rtime = pinfo[0].p_rtime_sec * clockrate 
78 +               + pinfo[0].p_rtime_usec  * clockrate / 1000000;
79 +       buf->frequency = clockrate;
80  #else
81         buf->rtime = tv2sec (pinfo [0].kp_proc.p_rtime);
82 +       buf->frequency = 1000000;
83  #endif
85 -       buf->frequency = 1000000;
86         buf->flags = _glibtop_sysdeps_proc_time;
88 -#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000)) || (defined(OpenBSD) && (OpenBSD >= 199912))
89 +#if (defined(__NetBSD__) && (__NetBSD_Version__ >= 104000000))
91 +       buf->utime = pinfo[0].p_uutime_sec * 1000000
92 +               + pinfo[0].p_uutime_usec;
93 +       buf->stime = pinfo[0].p_ustime_sec * 1000000
94 +               + pinfo[0].p_ustime_usec;
95 +       buf->cutime = pinfo[0].p_uctime_sec * 1000000
96 +               + pinfo[0].p_uctime_usec; /* XXX is u+s */
97 +       buf->cstime = 0; /* XXX */
98 +       buf->start_time = pinfo[0].p_ustart_sec;
100 +       buf->flags |= _glibtop_sysdeps_proc_time_user;
102 +#elif (defined(OpenBSD) && (OpenBSD >= 199912))
103         glibtop_suid_enter (server);
105         if (kvm_read (server->machine.kd,