From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44E86C433C1 for ; Thu, 25 Mar 2021 12:53:48 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AA41B619BF for ; Thu, 25 Mar 2021 12:53:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AA41B619BF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1lPPUG-00066b-8M; Thu, 25 Mar 2021 08:53:20 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94) (envelope-from ) id 1lPPUD-00066V-SO for kernelnewbies@kernelnewbies.org; Thu, 25 Mar 2021 08:53:18 -0400 Received: by mail-ed1-x530.google.com with SMTP id z1so2273192edb.8 for ; Thu, 25 Mar 2021 05:53:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=Mcb8elH2oe6HYyjhIKgsLiKCZusb2du+ILgvW2/I0qA=; b=pon0jMlJtg9MoU8p4UhOk+a9WDrSYbkscGA3pcWaXUTI6KeDHbm3uZ7AvkXoC9G8fN rfcdryphy5PKAuwAVxYz3GSN0Y1ZVPJpTlQctO3L57DqpHeX5rbexc6JBXIMjeINCTc1 D08PXyd5kU/Hnp4aDIOCXjKV8ZnIPodImyTcJy1MeUuZ4/B7TjGGfNAn7vgpm/jyPy88 MLMNeJ58OCQVG1ifm/D3529xW5mEAihob43pWCU/XB+sKGPJCSvS91AWwuPg3+ec9fX7 3pjkyIMMq5PGq4GvPS3nhDI/ndwKKGE8x/y011rqrQGO/sfYMNzx53KlVpJh/KutzifX qQEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Mcb8elH2oe6HYyjhIKgsLiKCZusb2du+ILgvW2/I0qA=; b=fyfVEw2WN2JfnGok4UuT8AnI/1XkIXccfwCeJOfsQnbHdVU4iRt/UXGbGcVpzglKZT Qku4RbqA+b4p6iTpaigMdSmc2q6GUfaWym5cxbes9clYQ1Gz3M1yLTVbdyE8zLPCQr4e Vtbr9SX6w8uaBlOdLMPnKuPihqUMKBgGIhwS/shjOYBK0VO3gn6Zcr5IxD/ersg6s+2v 8+x/RpARH5SxqGdZxrMngb8bA5xkM/qq1F4RpFqyV7phOfu92rzj/ARKVHb6XNIwtCBw BN4nNDZ2rFMT2BAlEQKB1JOG79oO6cms3JoO1VGpAIBvrEahOwVk7BGRwy+e0pWRlst2 PBCQ== X-Gm-Message-State: AOAM532EkOhHc+ktU/F0h+XsveSuA+oMnvxWIPaItvMkq15/K3UF00Ob XZ0C+zKlyoSS+r3UJte2SbAjQwPm3xdfbcWAha6bMSuUdfUQkQ== X-Google-Smtp-Source: ABdhPJxJBfAvaYaCBPJh88K5KwMwphhuKKPXZMj+kC+ZXzBiM+rGTNanTJ6I2+oVuXcKZlekxkzGNkYpE2maDgOqHnY= X-Received: by 2002:aa7:cf90:: with SMTP id z16mr8887147edx.273.1616676795211; Thu, 25 Mar 2021 05:53:15 -0700 (PDT) MIME-Version: 1.0 From: Navin P Date: Thu, 25 Mar 2021 18:23:03 +0530 Message-ID: Subject: pid start time and new display field in proc pid stat To: kernelnewbies@kernelnewbies.org X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kernelnewbies-bounces@kernelnewbies.org Hi, As of 5.11 kernel (pid,pid_start_time) is not unique /monotonic even though the underlying counters are . I chose start_boottime because i wanted the counter to increase during suspend as well. 1. Is there any case where task->start_boottime or ktime_get_boottime_ns doesn't become monotonic i.e increasing ? 2. If start_boottime is not monotonic which counter to use ? 3. If i create a new field in task_struct , then i can use a atomic_add_return(1,&v) to fill in the task->new_field. Will this also work ? By doing this becomes unique. In linux/fs/proc/array.c at line 566 we have /* apply timens offset for boottime and convert nsec -> ticks */ start_time = nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime)); task->start_boottime is a monotonic increasing counter fetched from ktime_get_boottime_ns in fork.c nsec_to_clock_t contains div_u64 due to which we loose some lower bits/digits on divison and is not unique unless the divisor is 1. if CONFIG_HZ = 250 and nsec_to_clock_t x=4000001 , then #if (NSEC_PER_SEC % USER_HZ) == 0 return div_u64(x, NSEC_PER_SEC / USER_HZ); becomes div_u64(x, 4000000) then return value is 1 when x=4000002, return value is 1 until x=8000000 which returns 2. The value shown in /proc/[pid]/stat is actually the truncated value. Hence i'm planning to display a counter at the end of /proc/[pid]/stat as the 53rd field. I've prepared a patch as inlined. >From a2c6b5d6435394f015d38700008ff74f16dfa5fd Mon Sep 17 00:00:00 2001 From: Navin P Date: Thu, 25 Mar 2021 15:27:30 +0530 Subject: [PATCH] Display task->start_boottime as 53rd field in /proc/[pid]/stat. The 22nd field start_time currently shown in /proc/[pid]/stat as start_time is truncated by division.Hence it is not unique . Signed-off-by: Navin P --- Documentation/filesystems/proc.rst | 1 + fs/proc/array.c | 1 + 2 files changed, 2 insertions(+) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index 48fbfc336ebf..3b7a1543b2c0 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -381,6 +381,7 @@ It's slow but very precise. env_end address below which program environment is placed exit_code the thread's exit_code in the form reported by the waitpid system call + start_boottime the process start time in nanoseconds since boot ============= =============================================================== The /proc/PID/maps file contains the currently mapped memory regions and diff --git a/fs/proc/array.c b/fs/proc/array.c index bb87e4d89cd8..74389aaefa9c 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -645,6 +645,7 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, else seq_puts(m, " 0"); + seq_put_decimal_ull(m, " ", task->start_boottime); seq_putc(m, '\n'); if (mm) mmput(mm); -- 2.25.1 _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies