From patchwork Thu Sep 7 22:42:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Albert ARIBAUD (3ADEV)" X-Patchwork-Id: 811246 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-84361-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="TPEau738"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xpFzT13dgz9rxl for ; Fri, 8 Sep 2017 08:50:44 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=dlKj2l6sHfptS5nPxtxGhMdn2K3kpp5 +sh1Yxppp1PRPuHQXkSXZULGverFcJm8shUv266pKFrHLhcW+t+nKOf+vRAFQ+p0 rzH+rg8N4Tl1wkpp0sN+ygX9HMaxB6QR1FWG0h6QPKEheZaqrPAhF0uXpraPfggi 70QmdRkUHN4U= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references; s=default; bh=iJHyNQNorUDZxKmNg3AIuaYch70=; b=TPEau 7381/IgJG6NF/ELR6kyYrwR4FnSyzOkPr7VXYlnikSLCy/A/ePqxsiKQg4Gu9ULS Qg/0Ah5coXJ4kym1tFTc6toNwT1m0k3zrFVNIZWNb5UmWlrlG1C6lgsYa/8WcwjQ nqViWH6clXg2U/7uYH5+EytRNW6eGVTu9DIIU4= Received: (qmail 121395 invoked by alias); 7 Sep 2017 22:45:35 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 121239 invoked by uid 89); 7 Sep 2017 22:45:35 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy= X-HELO: smtp6-g21.free.fr From: "Albert ARIBAUD (3ADEV)" To: libc-alpha@sourceware.org Cc: "Albert ARIBAUD (3ADEV)" Subject: [RFC PATCH 44/52] Y2038: add function __getrusage_t64 Date: Fri, 8 Sep 2017 00:42:11 +0200 Message-Id: <20170907224219.12483-45-albert.aribaud@3adev.fr> In-Reply-To: <20170907224219.12483-44-albert.aribaud@3adev.fr> References: <20170907224219.12483-1-albert.aribaud@3adev.fr> <20170907224219.12483-2-albert.aribaud@3adev.fr> <20170907224219.12483-3-albert.aribaud@3adev.fr> <20170907224219.12483-4-albert.aribaud@3adev.fr> <20170907224219.12483-5-albert.aribaud@3adev.fr> <20170907224219.12483-6-albert.aribaud@3adev.fr> <20170907224219.12483-7-albert.aribaud@3adev.fr> <20170907224219.12483-8-albert.aribaud@3adev.fr> <20170907224219.12483-9-albert.aribaud@3adev.fr> <20170907224219.12483-10-albert.aribaud@3adev.fr> <20170907224219.12483-11-albert.aribaud@3adev.fr> <20170907224219.12483-12-albert.aribaud@3adev.fr> <20170907224219.12483-13-albert.aribaud@3adev.fr> <20170907224219.12483-14-albert.aribaud@3adev.fr> <20170907224219.12483-15-albert.aribaud@3adev.fr> <20170907224219.12483-16-albert.aribaud@3adev.fr> <20170907224219.12483-17-albert.aribaud@3adev.fr> <20170907224219.12483-18-albert.aribaud@3adev.fr> <20170907224219.12483-19-albert.aribaud@3adev.fr> <20170907224219.12483-20-albert.aribaud@3adev.fr> <20170907224219.12483-21-albert.aribaud@3adev.fr> <20170907224219.12483-22-albert.aribaud@3adev.fr> <20170907224219.12483-23-albert.aribaud@3adev.fr> <20170907224219.12483-24-albert.aribaud@3adev.fr> <20170907224219.12483-25-albert.aribaud@3adev.fr> <20170907224219.12483-26-albert.aribaud@3adev.fr> <20170907224219.12483-27-albert.aribaud@3adev.fr> <20170907224219.12483-28-albert.aribaud@3adev.fr> <20170907224219.12483-29-albert.aribaud@3adev.fr> <20170907224219.12483-30-albert.aribaud@3adev.fr> <20170907224219.12483-31-albert.aribaud@3adev.fr> <20170907224219.12483-32-albert.aribaud@3adev.fr> <20170907224219.12483-33-albert.aribaud@3adev.fr> <20170907224219.12483-34-albert.aribaud@3adev.fr> <20170907224219.12483-35-albert.aribaud@3adev.fr> <20170907224219.12483-36-albert.aribaud@3adev.fr> <20170907224219.12483-37-albert.aribaud@3adev.fr> <20170907224219.12483-38-albert.aribaud@3adev.fr> <20170907224219.12483-39-albert.aribaud@3adev.fr> <20170907224219.12483-40-albert.aribaud@3adev.fr> <20170907224219.12483-41-albert.aribaud@3adev.fr> <20170907224219.12483-42-albert.aribaud@3adev.fr> <20170907224219.12483-43-albert.aribaud@3adev.fr> <20170907224219.12483-44-albert.aribaud@3adev.fr> Signed-off-by: Albert ARIBAUD (3ADEV) --- resource/Makefile | 2 +- resource/Versions | 7 ++ resource/getrusage64.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 1 deletion(-) create mode 100644 resource/getrusage64.c diff --git a/resource/Makefile b/resource/Makefile index 06bc7a2fb2..81a865105b 100644 --- a/resource/Makefile +++ b/resource/Makefile @@ -23,7 +23,7 @@ headers := sys/resource.h bits/resource.h sys/vlimit.h sys/vtimes.h \ ulimit.h bits/types/struct_rusage.h routines := getrlimit setrlimit getrlimit64 setrlimit64 getrusage ulimit \ - vlimit vtimes getpriority setpriority nice + vlimit vtimes getpriority setpriority nice getrusage64 tests = tst-getrlimit bug-ulimit1 diff --git a/resource/Versions b/resource/Versions index d6c2ccee1b..84f3a79769 100644 --- a/resource/Versions +++ b/resource/Versions @@ -25,4 +25,11 @@ libc { GLIBC_PRIVATE { __getrlimit; } + + # Y2038 symbols are given their own version until they can be put in + # the right place + + GLIBC_Y2038 { + __getrusage_t64; + } } diff --git a/resource/getrusage64.c b/resource/getrusage64.c new file mode 100644 index 0000000000..6c81137a8b --- /dev/null +++ b/resource/getrusage64.c @@ -0,0 +1,185 @@ +/* Copyright (C) 1996-2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include + +/* Structure which says how much of each resource has been used. */ +/* 64-bit time version */ +/* The purpose of all the unions is to have the kernel-compatible layout + while keeping the API type as 'long int', and among machines where + __syscall_slong_t is not 'long int', this only does the right thing + for little-endian ones, like x32. */ +struct __rusage_t64 + { + /* Total amount of user time used. */ + struct __timeval64 ru_utime; + /* Total amount of system time used. */ + struct __timeval64 ru_stime; + /* Maximum resident set size (in kilobytes). */ + __extension__ union + { + long int ru_maxrss; + __syscall_slong_t __ru_maxrss_word; + }; + /* Amount of sharing of text segment memory + with other processes (kilobyte-seconds). */ + /* Maximum resident set size (in kilobytes). */ + __extension__ union + { + long int ru_ixrss; + __syscall_slong_t __ru_ixrss_word; + }; + /* Amount of data segment memory used (kilobyte-seconds). */ + __extension__ union + { + long int ru_idrss; + __syscall_slong_t __ru_idrss_word; + }; + /* Amount of stack memory used (kilobyte-seconds). */ + __extension__ union + { + long int ru_isrss; + __syscall_slong_t __ru_isrss_word; + }; + /* Number of soft page faults (i.e. those serviced by reclaiming + a page from the list of pages awaiting reallocation. */ + __extension__ union + { + long int ru_minflt; + __syscall_slong_t __ru_minflt_word; + }; + /* Number of hard page faults (i.e. those that required I/O). */ + __extension__ union + { + long int ru_majflt; + __syscall_slong_t __ru_majflt_word; + }; + /* Number of times a process was swapped out of physical memory. */ + __extension__ union + { + long int ru_nswap; + __syscall_slong_t __ru_nswap_word; + }; + /* Number of input operations via the file system. Note: This + and `ru_oublock' do not include operations with the cache. */ + __extension__ union + { + long int ru_inblock; + __syscall_slong_t __ru_inblock_word; + }; + /* Number of output operations via the file system. */ + __extension__ union + { + long int ru_oublock; + __syscall_slong_t __ru_oublock_word; + }; + /* Number of IPC messages sent. */ + __extension__ union + { + long int ru_msgsnd; + __syscall_slong_t __ru_msgsnd_word; + }; + /* Number of IPC messages received. */ + __extension__ union + { + long int ru_msgrcv; + __syscall_slong_t __ru_msgrcv_word; + }; + /* Number of signals delivered. */ + __extension__ union + { + long int ru_nsignals; + __syscall_slong_t __ru_nsignals_word; + }; + /* Number of voluntary context switches, i.e. because the process + gave up the process before it had to (usually to wait for some + resource to be available). */ + __extension__ union + { + long int ru_nvcsw; + __syscall_slong_t __ru_nvcsw_word; + }; + /* Number of involuntary context switches, i.e. a higher priority process + became runnable or the current process used up its time slice. */ + __extension__ union + { + long int ru_nivcsw; + __syscall_slong_t __ru_nivcsw_word; + }; + }; + +extern int __y2038_linux_support; + +int __getrusage_t64 (__rusage_who_t __who, struct __rusage_t64 *__usage) +{ + int result; + struct rusage usage32; + + if (__y2038_linux_support) + { + // TODO: use 64-bit-time syscall if available + } + + result = INLINE_SYSCALL(getrusage, 2, __who, &usage32); + /* Copy fields from 32-bit into 64-bit rusage structure */ + /* Total amount of user time used. */ + __usage->ru_utime.tv_sec = usage32.ru_utime.tv_sec; + __usage->ru_utime.tv_usec = usage32.ru_utime.tv_usec; + /* Total amount of system time used. */ + __usage->ru_stime.tv_sec = usage32.ru_stime.tv_sec; + __usage->ru_stime.tv_usec = usage32.ru_stime.tv_usec; + /* Maximum resident set size (in kilobytes). */ + __usage->ru_maxrss = usage32.ru_maxrss; + /* Amount of sharing of text segment memory + with other processes (kilobyte-seconds). */ + /* Maximum resident set size (in kilobytes). */ + __usage->ru_ixrss = usage32.ru_ixrss; + /* Amount of data segment memory used (kilobyte-seconds). */ + __usage->ru_idrss = usage32.ru_idrss; + /* Amount of stack memory used (kilobyte-seconds). */ + __usage->ru_isrss = usage32.ru_isrss; + /* Number of soft page faults (i.e. those serviced by reclaiming + a page from the list of pages awaiting reallocation. */ + __usage->ru_minflt = usage32.ru_minflt; + /* Number of hard page faults (i.e. those that required I/O). */ + __usage->ru_majflt = usage32.ru_majflt; + /* Number of times a process was swapped out of physical memory. */ + __usage->ru_nswap = usage32.ru_nswap; + /* Number of input operations via the file system. Note: This + and `ru_oublock' do not include operations with the cache. */ + __usage->ru_inblock = usage32.ru_inblock; + /* Number of output operations via the file system. */ + __usage->ru_oublock = usage32.ru_oublock; + /* Number of IPC messages sent. */ + __usage->ru_msgsnd = usage32.ru_msgsnd; + /* Number of IPC messages received. */ + __usage->ru_msgrcv = usage32.ru_msgrcv; + /* Number of signals delivered. */ + __usage->ru_nsignals = usage32.ru_nsignals; + /* Number of voluntary context switches, i.e. because the process + gave up the process before it had to (usually to wait for some + resource to be available). */ + __usage->ru_nvcsw = usage32.ru_nvcsw; + /* Number of involuntary context switches, i.e. a higher priority process + became runnable or the current process used up its time slice. */ + __usage->ru_nivcsw = usage32.ru_nivcsw; + + return result; +}