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=-7.9 required=3.0 tests=DATE_IN_PAST_03_06, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT 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 86630C04E53 for ; Wed, 15 May 2019 07:05:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 62CF620881 for ; Wed, 15 May 2019 07:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725902AbfEOHFG (ORCPT ); Wed, 15 May 2019 03:05:06 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8193 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725877AbfEOHFG (ORCPT ); Wed, 15 May 2019 03:05:06 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id D60232200DE48C799F3A; Wed, 15 May 2019 15:05:03 +0800 (CST) Received: from huawei.com (10.175.104.225) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Wed, 15 May 2019 15:04:52 +0800 From: Ying Lv To: , CC: , , , , Subject: [PATCH] fix rasdaemon high CPU usage when part of CPUs offline Date: Wed, 15 May 2019 11:15:42 +0800 Message-ID: <20190515031542.13739-1-lvying6@huawei.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.225] X-CFilter-Loop: Reflected Sender: linux-edac-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org When we set part of CPU core offline, such as by setting the kernel cmdline maxcpus = N(N is less than the total number of system CPU cores). And then, we will observe that the CPU usage of some rasdaemon threads is very close to 100. This is because when part of CPU offline, poll in read_ras_event_all_cpus func will fallback to pthread way. Offlined CPU thread will return negative value when read trace_pipe_raw, negative return value will covert to positive value because of 'unsigned size'. So code will always go into 'size > 0' branch, and the CPU usage is too high. Here, variable size uses int type will go to the right branch. Fiexs: eff7c9e0("ras-events: Only use pthreads for collect if poll() not available") Reported-by: Zhipeng Xie Signed-off-by: Ying Lv --- ras-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ras-events.c b/ras-events.c index 9395f6f..1094df0 100644 --- a/ras-events.c +++ b/ras-events.c @@ -421,7 +421,7 @@ static int read_ras_event(int fd, struct kbuffer *kbuf, void *page) { - unsigned size; + int size; unsigned long long time_stamp; void *data; -- 2.21.0