Received: by 10.223.185.116 with SMTP id b49csp3580984wrg; Mon, 26 Feb 2018 02:28:28 -0800 (PST) X-Google-Smtp-Source: AG47ELv4rnq5AD8jtHfrwOP6eB2KJ2Dq363MzxKXIyvDMum4dcEI5nEM/aR5NDx7XU4K2O/AG7n6 X-Received: by 10.98.35.68 with SMTP id j65mr5610879pfj.5.1519640908550; Mon, 26 Feb 2018 02:28:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519640908; cv=none; d=google.com; s=arc-20160816; b=M3gauEGOozMA8qQkZmtQnrKVygWLarUQUyMTCzoOwrwIVoFbLOcP2aW8hAczDwepwu xQtgZjfvHrrnOuYHyy5EK0JjsQTyeK+Kmx8nDBz9NpDMn0SszeiRcv53WQYNqpximwjM WjuVu5JJQCriSCE60vXoijyQDYgKw3KxWufTpcLH0rEGgc13PLu4yEk9WpGm+r650P5f zKlU5froW+dcaOcXsORN4Bxc8rJmIC1ozIgxUI5alIQHeY/k8uj1tlpVyXTWZVRLkP7v ozthS0ibNQRDu7TdA8+Zp6Zt7CDmzCnjxK3PtrzyHSE+fLxQVOvpciUOwgFzcXzQNd7Z 7y+g== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=5sauy3QR6df0n9fMJwdHT3FwYvobYe7sSTumHBLtPsg=; b=Ia/GTL7GW3cUsN2SEbRudLoxu4Pqp9VIPD8jRrfcbLp66n2y2PwmbCsHituO1YZx23 mUzbQ3syzwi/BAGykwgW1PspajwS/JT6u80UV1l1xE9NkutgkMyx6/Q6u52o6ogBlzoB +utI+qbMstZwQbY+7EVxivoDIAK/ELfBZQr86j17ZSWSKjFd1gdMqOxc6woPyfzGLGv/ 0jhHOXPQaBr9tVz20c+ODtqD+95jwdIeq7tKXyW9qIjs1DcX0rjD+ALgG/3p14xwaon3 aOmmwxyNoZ7KnjJnvHGfKyIGhIf+/91Q85JK56JJQLnX684GAPAG8j61X6iEwbfqUACG Ekag== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f3-v6si360276plm.169.2018.02.26.02.28.14; Mon, 26 Feb 2018 02:28:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752733AbeBZK07 (ORCPT + 99 others); Mon, 26 Feb 2018 05:26:59 -0500 Received: from www62.your-server.de ([213.133.104.62]:52715 "EHLO www62.your-server.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752045AbeBZK0z (ORCPT ); Mon, 26 Feb 2018 05:26:55 -0500 Received: from [194.230.159.212] (helo=localhost.localdomain) by www62.your-server.de with esmtpsa (TLSv1.2:DHE-RSA-AES256-SHA:256) (Exim 4.85_2) (envelope-from ) id 1eqFzh-0005iI-52; Mon, 26 Feb 2018 11:26:53 +0100 Subject: Re: [PATCH bpf-next v2] samples/bpf: Add program for CPU state statistics To: Leo Yan , Alexei Starovoitov , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Jesper Dangaard Brouer Cc: Daniel Lezcano , Vincent Guittot References: <1519607952-12299-1-git-send-email-leo.yan@linaro.org> From: Daniel Borkmann Message-ID: <1e487d11-4f15-09e5-2f53-08b9b30e1494@iogearbox.net> Date: Mon, 26 Feb 2018 11:26:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <1519607952-12299-1-git-send-email-leo.yan@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Authenticated-Sender: daniel@iogearbox.net X-Virus-Scanned: Clear (ClamAV 0.99.3/24350/Mon Feb 26 10:14:06 2018) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/26/2018 02:19 AM, Leo Yan wrote: > CPU is active when have running tasks on it and CPUFreq governor can > select different operating points (OPP) according to different workload; > we use 'pstate' to present CPU state which have running tasks with one > specific OPP. On the other hand, CPU is idle which only idle task on > it, CPUIdle governor can select one specific idle state to power off > hardware logics; we use 'cstate' to present CPU idle state. > > Based on trace events 'cpu_idle' and 'cpu_frequency' we can accomplish > the duration statistics for every state. Every time when CPU enters > into or exits from idle states, the trace event 'cpu_idle' is recorded; > trace event 'cpu_frequency' records the event for CPU OPP changing, so > it's easily to know how long time the CPU stays in the specified OPP, > and the CPU must be not in any idle state. > > This patch is to utilize the mentioned trace events for pstate and > cstate statistics. To achieve more accurate profiling data, the program > uses below sequence to insure CPU running/idle time aren't missed: > > - Before profiling the user space program wakes up all CPUs for once, so > can avoid to missing account time for CPU staying in idle state for > long time; the program forces to set 'scaling_max_freq' to lowest > frequency and then restore 'scaling_max_freq' to highest frequency, > this can ensure the frequency to be set to lowest frequency and later > after start to run workload the frequency can be easily to be changed > to higher frequency; > > - User space program reads map data and update statistics for every 5s, > so this is same with other sample bpf programs for avoiding big > overload introduced by bpf program self; > > - When send signal to terminate program, the signal handler wakes up > all CPUs, set lowest frequency and restore highest frequency to > 'scaling_max_freq'; this is exactly same with the first step so > avoid to missing account CPU pstate and cstate time during last > stage. Finally it reports the latest statistics. > > The program has been tested on Hikey board with octa CA53 CPUs, below > is one example for statistics result, the format mainly follows up > Jesper Dangaard Brouer suggestion. > > Jesper reminds to 'get printf to pretty print with thousands separators > use %' and setlocale(LC_NUMERIC, "en_US")', tried three different arm64 > GCC toolchains (5.4.0 20160609, 6.2.1 20161016, 6.3.0 20170516) but all > of them cannot support printf flag character %' on arm64 platform, so go > back print number without grouping mode. > > CPU states statistics: > state(ms) cstate-0 cstate-1 cstate-2 pstate-0 pstate-1 pstate-2 pstate-3 pstate-4 > CPU-0 767 6111 111863 561 31 756 853 190 > CPU-1 241 10606 107956 484 125 646 990 85 > CPU-2 413 19721 98735 636 84 696 757 89 > CPU-3 84 11711 79989 17516 909 4811 5773 341 > CPU-4 152 19610 98229 444 53 649 708 1283 > CPU-5 185 8781 108697 666 91 671 677 1365 > CPU-6 157 21964 95825 581 67 566 684 1284 > CPU-7 125 15238 102704 398 20 665 786 1197 > > Cc: Daniel Lezcano > Cc: Vincent Guittot > Signed-off-by: Leo Yan Applied to bpf-next, thanks Leo!