Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2678330pxu; Sun, 18 Oct 2020 11:07:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwn/HJF2Ygtu4IL1KZdMJ+w/vxb2u1KQbHdBKNxG5QDLjCDyAcAwpF4kDga73WSFQcLP3I X-Received: by 2002:a05:6402:1bcc:: with SMTP id ch12mr14575189edb.339.1603044467458; Sun, 18 Oct 2020 11:07:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603044467; cv=none; d=google.com; s=arc-20160816; b=XK4tF0BgpGtWizwXXzmdKAYRwIXcNxYXtlkleXlFJ8d26Ihu3lpWNdey98MPlfu7cn wK4GOROrnJ8xukbVywIP/U9jeoH+ZTT/XaDSjudnXW29nlrbsjJkiGmQlUCXuqztGpgZ yXPJ7htilUCnwFVDFmBZebNw79BG3m3uCMDiR8zYr1J892/gIrLXJgx3MTVNG6UITOQJ ENymVVJRjBA+I3mNLl8aO5feXeqxULEoTXyTAllkNVhkQVbggbxAz0JWxWdtS8BrctBC KME9R1aoolwSsWc4zSc6/bjmbLVWeopmCk390FA9CZyT4j1UA2RgFnG2LxDjqLrsh9DK vpaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date:dkim-signature; bh=IX5bOBLgQ3MVI8RGcDJwWiaWttwwGpXgmD0PVSnmAt4=; b=HzE1uyGmLTBmBKl3nwfmlr/fxTIwBjTY5VGoq+EpTD2wj25gdJbqZjCrOByOzJgah4 oBqyil5csN3LQHbBuYgR8p/mZZYdS0V7nc7vV361tU2riD+FIEu+plIMmpV6D2abyOkI 8tmfuyfIth/R8IT15aqDymERCaONaXbBhSEck7xVKm8wp0T/LhMwM6008452kiKh8JjF SAnpoocd05FkySiKny/61aRlioGgbNfNqp8MU4bLLw0Kwxm4OhCC4u4wMqXfSQWEnm3Y U7kPfcDKttBNByxPO7mSKk3k6Vp4SzBeVh8XU4hDgpKkWXKi6cseLRAo8tny5BUdmZPQ qQnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=hcDCtaDv; 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=NONE dis=NONE) header.from=163.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ny23si6007637ejb.586.2020.10.18.11.07.24; Sun, 18 Oct 2020 11:07:47 -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=@163.com header.s=s110527 header.b=hcDCtaDv; 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=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726765AbgJRRGQ (ORCPT + 99 others); Sun, 18 Oct 2020 13:06:16 -0400 Received: from m12-14.163.com ([220.181.12.14]:56698 "EHLO m12-14.163.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726357AbgJRRGQ (ORCPT ); Sun, 18 Oct 2020 13:06:16 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:Message-ID:MIME-Version; bh=IX5bO BLgQ3MVI8RGcDJwWiaWttwwGpXgmD0PVSnmAt4=; b=hcDCtaDvh4kPS2LlEH1km L5JUqtKl6dElNGm7Bns0JgF0TzAv4TAbde5CFp5Bi4bETLvfmaL1aBxKr3/pJNwX sS9ubA476NEAC44WKpXGfl/mkX5F+7wXRAPkVbDmza24kHV6Zp9kBCFgfPKEhFv8 DBZ9Hyv6E4AnPMUQfcyW+s= Received: from localhost (unknown [101.86.214.18]) by smtp10 (Coremail) with SMTP id DsCowADnnbT2dYxfkWtyQw--.18878S2; Mon, 19 Oct 2020 01:05:58 +0800 (CST) Date: Mon, 19 Oct 2020 01:05:57 +0800 From: Hui Su To: corbet@lwn.net, dsterba@suse.com, mchehab+huawei@kernel.org, sh_def@163.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] docs/cpu-load: format the example code. Message-ID: <20201018170557.GA7670@rlk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-CM-TRANSID: DsCowADnnbT2dYxfkWtyQw--.18878S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Kw1fCr1xXF47Aw4fZryrJFb_yoW8ZrWUp3 yUAan2qrZ5Ga4UCa4UA3yxGFnxX34I9an0gr42k3s5t397Aws5ta4Iyr1jyF4fCrWxJay7 ArZIgF15uF45C37anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UprW7UUUUU= X-Originating-IP: [101.86.214.18] X-CM-SenderInfo: xvkbvvri6rljoofrz/1tbiWRbBX1WBtDepWAAAs3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org format the example code. Signed-off-by: Hui Su --- Documentation/admin-guide/cpu-load.rst | 63 ++++++++++++++------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/Documentation/admin-guide/cpu-load.rst b/Documentation/admin-guide/cpu-load.rst index ebdecf864080..f3ada90e9ca8 100644 --- a/Documentation/admin-guide/cpu-load.rst +++ b/Documentation/admin-guide/cpu-load.rst @@ -61,43 +61,46 @@ will lead to quite erratic information inside ``/proc/stat``:: static volatile sig_atomic_t stop; - static void sighandler (int signr) + static void sighandler(int signr) { - (void) signr; - stop = 1; + (void) signr; + stop = 1; } + static unsigned long hog (unsigned long niters) { - stop = 0; - while (!stop && --niters); - return niters; + stop = 0; + while (!stop && --niters); + return niters; } + int main (void) { - int i; - struct itimerval it = { .it_interval = { .tv_sec = 0, .tv_usec = 1 }, - .it_value = { .tv_sec = 0, .tv_usec = 1 } }; - sigset_t set; - unsigned long v[HIST]; - double tmp = 0.0; - unsigned long n; - signal (SIGALRM, &sighandler); - setitimer (ITIMER_REAL, &it, NULL); - - hog (ULONG_MAX); - for (i = 0; i < HIST; ++i) v[i] = ULONG_MAX - hog (ULONG_MAX); - for (i = 0; i < HIST; ++i) tmp += v[i]; - tmp /= HIST; - n = tmp - (tmp / 3.0); - - sigemptyset (&set); - sigaddset (&set, SIGALRM); - - for (;;) { - hog (n); - sigwait (&set, &i); - } - return 0; + int i; + struct itimerval it = { + .it_interval = { .tv_sec = 0, .tv_usec = 1 }, + .it_value = { .tv_sec = 0, .tv_usec = 1 } }; + sigset_t set; + unsigned long v[HIST]; + double tmp = 0.0; + unsigned long n; + signal(SIGALRM, &sighandler); + setitimer(ITIMER_REAL, &it, NULL); + + hog (ULONG_MAX); + for (i = 0; i < HIST; ++i) v[i] = ULONG_MAX - hog(ULONG_MAX); + for (i = 0; i < HIST; ++i) tmp += v[i]; + tmp /= HIST; + n = tmp - (tmp / 3.0); + + sigemptyset(&set); + sigaddset(&set, SIGALRM); + + for (;;) { + hog(n); + sigwait(&set, &i); + } + return 0; } -- 2.25.1