Search code examples
cunixsolaris

comparison between starttime in struct proc and struct psinfo_t in solaris


In Solaris,
I need to get process start time from kernel space, and from user space.
I find 2 start time for a given process, and they are not equal !
One is located in proc struct (link is old but the struct almost identical) and one is on ps_info struct.
During execution, in kernel space, if i use

struct proc* iterated_process_ptr = curproc;

I get the following struct:

typedef struct  proc {
/*
 * Microstate accounting, resource usage, and real-time profiling
 */
hrtime_t p_mstart;      /* hi-res process start time */

And if i fill psinfo_t from user space struct like this:

char psfile[64];
psinfo_t psinfo;
sprintf(psfile, "/proc/ProcessID/psinfo");
if ((fd = open(psfile, O_RDONLY)) >= 0)
    if (read(fd, &psinfo, sizeof(psinfo_t)) != -1)     

the struct psinfo is filled, it looks like:

typedef struct psinfo {
timestruc_t pr_start;   /* process start time, from the epoch */

What is the difference between 2 start times ?

If i do it for the same process, the values are different, this means that hi-res process start time is different from process epoch start time.

What is hi-res process start ?

Thanks


Solution

  • The p_mstart field of the structure is filled in here in OpenSolaris (see line 1008) under the fork() system call:

        /*
         * Make proc entry for child process
         */
        mutex_init(&cp->p_splock, NULL, MUTEX_DEFAULT, NULL);
        mutex_init(&cp->p_crlock, NULL, MUTEX_DEFAULT, NULL);
        mutex_init(&cp->p_pflock, NULL, MUTEX_DEFAULT, NULL);
    #if defined(__x86)
        mutex_init(&cp->p_ldtlock, NULL, MUTEX_DEFAULT, NULL);
    #endif
        mutex_init(&cp->p_maplock, NULL, MUTEX_DEFAULT, NULL);
        cp->p_stat = SIDL;
        cp->p_mstart = gethrtime();
        cp->p_as = &kas;
    

    Per the man page for gethrtime():

    The gethrtime() function returns the current high-resolution real time. Time is expressed as nanoseconds since some arbitrary time in the past; it is not correlated in any way to the time of day

    So, the p_mstart field is filled with a time that can be used to determine exactly how many nanoseconds ago the process started, via a difference with with the return value of a current call to gethrtime():

    hrtime_t duration = gethrtime - p->p_mstart;