Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4022008ybz; Mon, 20 Apr 2020 14:03:21 -0700 (PDT) X-Google-Smtp-Source: APiQypKOwXDrf6wv32233cAFw305RbXMpblPby2BoSf29OZ0jgdUY92c20CVowvSdymKxA9Nmti0 X-Received: by 2002:aa7:daca:: with SMTP id x10mr15348954eds.59.1587416601438; Mon, 20 Apr 2020 14:03:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587416601; cv=none; d=google.com; s=arc-20160816; b=a0X30NMMfvyYTCt/4Iqc2JNQNDHWQvIM7bNL4DbFS31v0i2rkJznn0jdhibYNUPSSV V/4KjtrrRvIRO7g6g0tBA/TI7N12AWCAUdyrIZO7Bb4T8mHNVkAi8jQMMuNxETxnPsdI 5IOTfCxJntXZN/HFsJoTtcWD80dYVzKRzGJ/400SPxXyQDrTKkwbXp1lspM4hVu8s87Q +jY16YTuL+hJVTktuaWM8BrPkxaJprfIlXKEKwxp9KLLP26lyv0E0llf10ZICoumc3Qp iiByMZZfmon7PzWGMZi42WsVJXAJfHiZACgefnF1cbpg/UngzLp4ZyS5xR7dxZ4e4VZ5 a7EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+HzqPqoWK1aNcRwETf7TNa4PDAUr2rRyDa5sLUlM5fg=; b=FGyp3I7taEIrMhGaQF8Cx9SuOR5cUc0dJWE1u/ZdtjsIGau3tuAzba051DzUYKvSGd OWhtnQaoEQV8/BvhzCpyyqJJeAE/tB29jdZWeOXlikXdSYKrzHKhqpUUBijMG3NzH3Au yy8tbdP/iRZN61G0eY8QmtMcdVue2wjuTis/61fDALMywE0lf9jwoqARgSi6AA7dhKAZ sZHxAkUBgSFNqk36/7gnCK7EJ80lgAtZsVv1Ds4VOR6SyINHtta6V7sQu9+wn4+NmI0N mIgcOWJ/IopYLxcwykGOiCHuwnCilhfnrVTCGux+hR5aQ0TQk6h+iLEHQiBxmcozf97S za1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q6Xalzey; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f4si198129ejf.337.2020.04.20.14.02.52; Mon, 20 Apr 2020 14:03:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q6Xalzey; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728371AbgDTU67 (ORCPT + 99 others); Mon, 20 Apr 2020 16:58:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727075AbgDTU6O (ORCPT ); Mon, 20 Apr 2020 16:58:14 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50642C061A0E; Mon, 20 Apr 2020 13:58:14 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id r26so1192563wmh.0; Mon, 20 Apr 2020 13:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+HzqPqoWK1aNcRwETf7TNa4PDAUr2rRyDa5sLUlM5fg=; b=Q6XalzeytgTUsS7Iy2MW/hsb3wdDHB0fSQPRCb7J/7t9YS+HiELNVUKWJPI+2DX4Id mMAyLO6f//ZHyFPUt4l/0gdX7JM7vC/MBCifJlhNQX2hnwEncA6nueaMNPENAeun6CRg /tGhWC4DoUk3jQSdMErkTqyU5LaQUPsJJG7shkJrGKvxzewrAqS6MByxKbdQwyrsGaSl r5wEo+fWXNImiP4bTXPkkkgIbk3zcHPFXH9VLdx8rnIMmKGbBa59VNcEm3tpYd4nx0EG q8kUjUu4YVH2LBMDPJgGTJ2rjC3aeqV2l43NIbz6XnIwZnqp+q88DNzqwQtd8c0lOToi L6VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+HzqPqoWK1aNcRwETf7TNa4PDAUr2rRyDa5sLUlM5fg=; b=WJVTParsk4SkenyA+o74Ran08BBgRQt7dUZSlGRud3EYKvdUZp3xZWgpHkyJvgHEXG ir12hVNmq5ttm4d34RWhmSXV0Fs1Nyi9P/jbMGSCHdEPUX2z23GPErikHh9Bt8S7Sd1i GIjl8imkHf6IPRqU2rxItx4vlmxqS+vrkksQlxsLOEKGwIimbHFpQ0o+ijK9I7A62na2 /28QaOgSJvnyiKjD7WdJbfsdMHiFxq8mxAMKsZr/SGQ8rD4wnd13d4PySLiLUwrgJMd8 d2yhxeMCoy8mNWB0zwfTyAlSNC4M9+BLK2+HvdKMbRCGYS1NGFDKVqxQcqF71O8qmHVb m5jg== X-Gm-Message-State: AGi0PuZaidfYEoHMUNA3UABF3NB7iSsrhoPw2z+qzOjeZt3yFP2Tnasa igCM51+JO/lf1BK3NUcdng== X-Received: by 2002:a1c:a7c2:: with SMTP id q185mr1323029wme.42.1587416293086; Mon, 20 Apr 2020 13:58:13 -0700 (PDT) Received: from avx2.telecom.by ([46.53.249.74]) by smtp.gmail.com with ESMTPSA id m8sm863069wrx.54.2020.04.20.13.58.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 13:58:12 -0700 (PDT) From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: adobriyan@gmail.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, pmladek@suse.com, rostedt@goodmis.org, sergey.senozhatsky@gmail.com, andriy.shevchenko@linux.intel.com, linux@rasmusvillemoes.dk Subject: [PATCH 06/15] print_integer, proc: rewrite /proc/loadavg via print_integer() Date: Mon, 20 Apr 2020 23:57:34 +0300 Message-Id: <20200420205743.19964-6-adobriyan@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200420205743.19964-1-adobriyan@gmail.com> References: <20200420205743.19964-1-adobriyan@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Alexey Dobriyan --- fs/proc/loadavg.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/proc/loadavg.c b/fs/proc/loadavg.c index f32878d9a39f..4540a894db22 100644 --- a/fs/proc/loadavg.c +++ b/fs/proc/loadavg.c @@ -9,19 +9,33 @@ #include #include #include +#include "../../lib/print-integer.h" static int loadavg_proc_show(struct seq_file *m, void *v) { unsigned long avnrun[3]; + char buf[3 * (LEN_UL + 1 + 2 + 1) + 10 + 1 + 10 + 1 + 10 + 1]; + char *p = buf + sizeof(buf); + int i; + + *--p = '\n'; + p = _print_integer_u32(p, idr_get_cursor(&task_active_pid_ns(current)->idr) - 1); + *--p = ' '; + p = _print_integer_u32(p, nr_threads); + *--p = '/'; + p = _print_integer_u32(p, nr_running()); get_avenrun(avnrun, FIXED_1/200, 0); + for (i = 2; i >= 0; i--) { + *--p = ' '; + --p; /* overwritten */ + *--p = '0'; /* conditionally overwritten */ + (void)_print_integer_u32(p + 2, LOAD_FRAC(avnrun[i])); + *--p = '.'; + p = _print_integer_ul(p, LOAD_INT(avnrun[i])); + } - seq_printf(m, "%lu.%02lu %lu.%02lu %lu.%02lu %u/%d %d\n", - LOAD_INT(avnrun[0]), LOAD_FRAC(avnrun[0]), - LOAD_INT(avnrun[1]), LOAD_FRAC(avnrun[1]), - LOAD_INT(avnrun[2]), LOAD_FRAC(avnrun[2]), - nr_running(), nr_threads, - idr_get_cursor(&task_active_pid_ns(current)->idr) - 1); + seq_write(m, p, buf + sizeof(buf) - p); return 0; } -- 2.24.1