From patchwork Fri Feb 16 21:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 202360 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:c619:b0:108:e6aa:91d0 with SMTP id hn25csp784534dyb; Fri, 16 Feb 2024 13:04:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWkWi9NDJTdWd1JLhrU3m0W3FiPl2XV03fItFiBbZjptyxE9j2xoL3NRqLv+cldz8esa7gwvGJuYWArHgSDTYMOrcWtNw== X-Google-Smtp-Source: AGHT+IHM3qwrecG1bzNriM7UjtKJINTwBfxvhpHopJqOk6QIZVEKxCOtVGGe2yeup5g1/0cR6+fO X-Received: by 2002:a05:622a:134e:b0:42c:3928:86f3 with SMTP id w14-20020a05622a134e00b0042c392886f3mr6613103qtk.49.1708117460139; Fri, 16 Feb 2024 13:04:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708117460; cv=pass; d=google.com; s=arc-20160816; b=I4rUWSCPoSID9DZ6J4DvgNp8Tx2LVu+Py7OQiEMNOuv4MoLYcp1o1Cf2v4EsAII4iX a16Lk6Oxz5BqWZ4jWuxh9h2gNMPRbf+gY+yOSB4hV7M6WCsCzktf1U00JHw2CZkgzNUP LnNyL2ENN0PB8cpg3RFKYjTIz/43/eVNT9V/wLPOvBP46bCF88Jaunq1dR5XmFEuZnBq nHA/zoUzODSTn6vavRDWyyzgKRvJh0RZkgqmYZ7+1FvPuwqiDvlsbbdOHPe5+QMIgXKs /UYyQdf2sBSwd46GAC8HPKErbytwCOjs8NENTvfLyfwxMADno+v7wC0BOjdl94XOx/6q CJCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=Jwgt7j942b+RtdviLkqQv/0bhaDWr1d3Jx1c5jGJnhA=; fh=agDjUWYo9fuGLwPVzoFqoP6tQUAdz5VzwVjdQhFyOi4=; b=dDZPBPu4KSs4j5UQzjtxUEN104GFRNN9bsBOai4XuyTWU+ugmAPqDZvDtcVBby43qc TN9FHIR+0CwBxX/EX8mUZVrqYDFSWi7qdaum+KfiwGA781wxQqc1Xpeg1j2nanuZQoKj YqI3wk6F53oR/iX6333FdhON/EM+UDUPaZct+x2hkFGRTJP+UwmXvIqfS3x/cDqzt1SQ Jjka/bL2NdOsxpYRUhJl+WgP1QzpLHWRM12Wmbg+nPZcG2dCe8G6y3x5kox7BE99UQ5u +ebILJITVtpNmxXB/KtaE3jSEjA0JHgRCDSGM3o/hnWYEFBPzrWVdzRG+3YDa/bikuly hhGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-69336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69336-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z21-20020ac87115000000b0042da968cef7si603525qto.543.2024.02.16.13.04.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 13:04:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-69336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69336-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3983C1C268A4 for ; Fri, 16 Feb 2024 21:00:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A825C14691C; Fri, 16 Feb 2024 21:00:15 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25FA513AA56; Fri, 16 Feb 2024 21:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708117214; cv=none; b=u6tR3lj6FzIjmMIL5n4ZaaXXE4MDS4zUAIe7w9BPhsMtC3VBc6ZVJHzwy4ZnevMhZGF9prrENJyzPqOXEF4t08OhIqr1FL6PUVG7Q+tDwyrSA5/pabjV8nvScuW9iqDpX3pq4/lHGTqPjTs6tngv7WmjPcGOc2PkC7FBqd5k3Uw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708117214; c=relaxed/simple; bh=IvJLYtp9gt0fmSVqCctuit/Iiv1PQ8JuaI+bo/Qc3cE=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=JS5s3w92A/lTibTvMoDkCoFZl+8rb1X3lV6/sKkIvsoM+5DJthA6hhFKBoiuiK0D7kQ53PFSiyCKYnk5SJG9V9qRXQO0Nl7LwLAuVshnR/q2WD8GMQppBFfFlycUp2lQK6Tjiq0590GYJLUOsMrT2FVInCLRIUa28A62zjQfs4U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A014FC43394; Fri, 16 Feb 2024 21:00:13 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rb5LC-000000013CK-2oJd; Fri, 16 Feb 2024 16:01:50 -0500 Message-ID: <20240216210150.538844551@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 16 Feb 2024 16:00:49 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tim Chen , Vincent Donnefort , Sven Schnelle , Mete Durlu Subject: [PATCH v3 2/3] tracing: Move open coded processing of tgid_map into helper function References: <20240216210047.584712062@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791090973736366519 X-GMAIL-MSGID: 1791090973736366519 From: "Steven Rostedt (Google)" In preparation of moving the saved_cmdlines logic out of trace.c and into trace_sched_switch.c, replace the open coded manipulation of tgid_map in set_tracer_flag() into a helper function trace_alloc_tgid_map() so that it can be easily moved into trace_sched_switch.c without changing existing functions in trace.c. No functional changes. Signed-off-by: Steven Rostedt (Google) --- kernel/trace/trace.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 7a96e5cfe266..00fe323b96d5 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -5433,10 +5433,31 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set) return 0; } -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) +static int trace_alloc_tgid_map(void) { int *map; + if (tgid_map) + return 0; + + tgid_map_max = pid_max; + map = kvcalloc(tgid_map_max + 1, sizeof(*tgid_map), + GFP_KERNEL); + if (!map) + return -ENOMEM; + + /* + * Pairs with smp_load_acquire() in + * trace_find_tgid_ptr() to ensure that if it observes + * the tgid_map we just allocated then it also observes + * the corresponding tgid_map_max value. + */ + smp_store_release(&tgid_map, map); + return 0; +} + +int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) +{ if ((mask == TRACE_ITER_RECORD_TGID) || (mask == TRACE_ITER_RECORD_CMD)) lockdep_assert_held(&event_mutex); @@ -5459,20 +5480,7 @@ int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled) trace_event_enable_cmd_record(enabled); if (mask == TRACE_ITER_RECORD_TGID) { - if (!tgid_map) { - tgid_map_max = pid_max; - map = kvcalloc(tgid_map_max + 1, sizeof(*tgid_map), - GFP_KERNEL); - - /* - * Pairs with smp_load_acquire() in - * trace_find_tgid_ptr() to ensure that if it observes - * the tgid_map we just allocated then it also observes - * the corresponding tgid_map_max value. - */ - smp_store_release(&tgid_map, map); - } - if (!tgid_map) { + if (trace_alloc_tgid_map() < 0) { tr->trace_flags &= ~TRACE_ITER_RECORD_TGID; return -ENOMEM; }