Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4774833pxj; Tue, 22 Jun 2021 07:47:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxCjMDBPvoFTpDFWUlYxvjZ4A4dTZY+Wiowewb4Ed7EcaP7nczz2t5oJh1X4vnFNkZBsSY3 X-Received: by 2002:a17:907:7708:: with SMTP id kw8mr4532632ejc.111.1624373277061; Tue, 22 Jun 2021 07:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624373277; cv=none; d=google.com; s=arc-20160816; b=XQ9/SciONNMk12zRLjg9XM7JU4hJMcpTYlpIQWcurVGAtFiQQHKcot0f4tZ/6MeXgN uTFAtaVOKLYo098kVWQYKacVtIIjIaPXt4R90tGFdPBNiQ3v61Xh06uBaDvLoybN2jon Utg7QmQumXb5/q9M5bba0tXq7M7qJMkh4n2S136y+yf/sBq1YRa//xBMfF+bnyAtfvyl WrPvavi0rTgLNNY+deSAAoq06nO1zFuiDabYSBKaSQC8OUyxPFWYvvenFNka/JLqS0zr FTdMdbkUXuL9OFKre3+ILcAy2QccaiU1MV5173MLnaeXNyYE6XLFy+6nXSJxa4CEBr+D QDNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2Zi1Jmc7PpFitMHz4fgLN9ayTf1QzlW/J4F/Jv6tk2I=; b=H55YYXyQkqfIy5nC56Fgl1Kr7/YLEMlg2EE/NUY/cNc/o1USVb8mRe15l3AEOj5VYu LsBeJO2VqxdMvEQ5XcWO4l+a3TmJCZCssh3JZ0s1fY1JcslC4LSOx8/Om95HURskK6Dx B//vmikGL3OoOS/ZLCXC54okkSR1b+WE6VdQ1EAVcjOmX7e9fBJ3Lt89/n4JeSWjh1Kd zIUaZiSMpHuC8eORay9tuVWdWGfgmSLAOsgPgeOKITabijrOgtKxiB5LcFpAm8X9JsB3 MOEuGOyyRPdOQyFqiHMiQ7yvFjwTEhuw8FH1sEDHzP/Q/RyAm2MbvO9MwA6vF/yHqRM2 61Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZWpHBy79; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ds7si16140870ejc.670.2021.06.22.07.47.32; Tue, 22 Jun 2021 07:47:57 -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=@redhat.com header.s=mimecast20190719 header.b=ZWpHBy79; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232099AbhFVOrT (ORCPT + 99 others); Tue, 22 Jun 2021 10:47:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29570 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230185AbhFVOrR (ORCPT ); Tue, 22 Jun 2021 10:47:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624373101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2Zi1Jmc7PpFitMHz4fgLN9ayTf1QzlW/J4F/Jv6tk2I=; b=ZWpHBy79I0YggXKUcmw163L09j0GP0QKo6yXNjvqnODpE2IdrILO/FBPletvXAaJq2pFu3 WB7DZu/FCcLFKW7JH8MOS474GumnuAHM/IOAc5vESyD7uRC6djZakgWWDDdpbZ+sdWA3qM mqh953mLJLFxGkq+/XEuVuQEv4D1SfQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-36-wy3rKc9tMKuGIna2unZOzA-1; Tue, 22 Jun 2021 10:45:00 -0400 X-MC-Unique: wy3rKc9tMKuGIna2unZOzA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6DB2191272; Tue, 22 Jun 2021 14:44:57 +0000 (UTC) Received: from x1.bristot.me.homenet.telecomitalia.it (unknown [10.10.115.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id B168F5D9CA; Tue, 22 Jun 2021 14:44:49 +0000 (UTC) From: Daniel Bristot de Oliveira To: Steven Rostedt Cc: Phil Auld , Sebastian Andrzej Siewior , Kate Carcia , Daniel Bristot de Oliveira , Jonathan Corbet , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Alexandre Chartre , Clark Willaims , John Kacur , Juri Lelli , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V5 13/14] trace/hwlat: Support hotplug operations Date: Tue, 22 Jun 2021 16:42:31 +0200 Message-Id: <52012d25ea35491a0f8088b947864d8df8e25157.1624372313.git.bristot@redhat.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Enable and disable hwlat thread during cpu hotplug online and offline operations, respectivelly. Cc: Jonathan Corbet Cc: Steven Rostedt Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Alexandre Chartre Cc: Clark Willaims Cc: John Kacur Cc: Juri Lelli Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: x86@kernel.org Cc: linux-doc@vger.kernel.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Daniel Bristot de Oliveira --- kernel/trace/trace_hwlat.c | 65 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/kernel/trace/trace_hwlat.c b/kernel/trace/trace_hwlat.c index dc30b8a9bd5f..e13b8c836995 100644 --- a/kernel/trace/trace_hwlat.c +++ b/kernel/trace/trace_hwlat.c @@ -466,6 +466,7 @@ static void stop_cpu_kthread(unsigned int cpu) kthread = per_cpu(hwlat_per_cpu_data, cpu).kthread; if (kthread) kthread_stop(kthread); + per_cpu(hwlat_per_cpu_data, cpu).kthread = NULL; } /* @@ -506,6 +507,68 @@ static int start_cpu_kthread(unsigned int cpu) return 0; } +#ifdef CONFIG_HOTPLUG_CPU +static void hwlat_hotplug_workfn(struct work_struct *dummy) +{ + struct trace_array *tr = hwlat_trace; + unsigned int cpu = smp_processor_id(); + + mutex_lock(&trace_types_lock); + mutex_lock(&hwlat_data.lock); + get_online_cpus(); + + if (!hwlat_busy || hwlat_data.thread_mode != MODE_PER_CPU) + goto out_unlock; + + if (!cpumask_test_cpu(cpu, tr->tracing_cpumask)) + goto out_unlock; + + start_cpu_kthread(cpu); + +out_unlock: + put_online_cpus(); + mutex_unlock(&hwlat_data.lock); + mutex_unlock(&trace_types_lock); +} + +static DECLARE_WORK(hwlat_hotplug_work, hwlat_hotplug_workfn); + +/* + * hwlat_cpu_init - CPU hotplug online callback function + */ +static int hwlat_cpu_init(unsigned int cpu) +{ + schedule_work_on(cpu, &hwlat_hotplug_work); + return 0; +} + +/* + * hwlat_cpu_die - CPU hotplug offline callback function + */ +static int hwlat_cpu_die(unsigned int cpu) +{ + stop_cpu_kthread(cpu); + return 0; +} + +static void hwlat_init_hotplug_support(void) +{ + int ret; + + ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "trace/hwlat:online", + hwlat_cpu_init, hwlat_cpu_die); + if (ret < 0) + pr_warn(BANNER "Error to init cpu hotplug support\n"); + + return; +} +#else /* CONFIG_HOTPLUG_CPU */ +static void hwlat_init_hotplug_support(void) +{ + return; +} +#endif /* CONFIG_HOTPLUG_CPU */ + /* * start_per_cpu_kthreads - Kick off the hardware latency sampling/detector kthreads * @@ -822,6 +885,8 @@ __init static int init_hwlat_tracer(void) if (ret) return ret; + hwlat_init_hotplug_support(); + init_tracefs(); return 0; -- 2.31.1