Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp189738lqp; Thu, 4 Apr 2024 10:12:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXtbFXjL7dk9c3xXWV8KnJGvvlUKkSFwxdUheUG8P/1UZv6/J3siwfIr41FxQch2Sq1zJ1tjPY9BAhJeDdnJcBlmSu8DyXysvtTTtmjuA== X-Google-Smtp-Source: AGHT+IEGOLR70/D2A96gjqJ9G9XtQwoN8OCdySLSsjwtKPL/pXbh0z8ChOaW0T1yTuf8P/R+tnQQ X-Received: by 2002:a05:622a:451:b0:431:5f79:6748 with SMTP id o17-20020a05622a045100b004315f796748mr351477qtx.51.1712250750047; Thu, 04 Apr 2024 10:12:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712250750; cv=pass; d=google.com; s=arc-20160816; b=guGaCyOHwh2erW/HHrp1OzD+VtpSmDZsR3mlacLX8O8O8dbPdXhVCy7FN696t9n8bB HNK3149ZpmxGZ+ayrcHswx/YWhL9K2UPcTKSqSmtaKhixxT4Cj5PhDlCyhaS843Ao3in kbmgyXQv8Y4eWKVPrca8ClEw1QgHf0u265xHkTkt8XSjY/7R/x2waYnUTa7OKKAL+qYp R9jnXBQX/WjOHCoM3t1N689NHbaBH0IjSRTqf5AUEj5ao/m8PmfGcqiR/PJdqNnnIi6s XWYylltnlHo/G3ajfnnFhC4zkT8BYSUjl4ce/VniyK1UqK9Xn5NqsrLKKffHulOX93u9 0Nfw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=q6FK1VS2gwPNwOAqEWsX+MtO/8BcmvlPRF7XgH2ifUQ=; fh=JXROtR/v77zDyJnKXsQ1uL/Od6ef5T6BdmyrNcniUwA=; b=avDG8Tw+xegHAvlgTgkaxG413IY2ahB0Ab0OUg3VbjQmtQCNtqZwaYfkD0KE/Rpkm/ +Fwv27tktSp9iCPK4fwzz99tDHpb95KgBjUfp8Xn5lv1OSo3R6s9UUFNycGj5OBMz7vf kjw2osn9BxIGYntbM8KFP7jRUQzt2azAAguHN74ZSeAQxBLbM/uoeRXMrEas2g0xHDud xYp5EE+RF6kEOdPU+mjZwySx2irAzMSUCxaOoosoEzRrELa9ZWGl0Bd5SpOhcyQrDHMV xIQH6zlWfERFDyVsZ4r+PG4Cuju0VhAKQ7LTaJuWZMpVlUmok2KaJnwolWvwhyH5+ljN alOw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ty8ehNe8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131564-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c4-20020ac87dc4000000b00431627d735asi17284837qte.548.2024.04.04.10.12.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 10:12:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-131564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Ty8ehNe8; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-131564-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-131564-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 DDC7D1C28420 for ; Thu, 4 Apr 2024 14:09:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18BAB12DD9E; Thu, 4 Apr 2024 14:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ty8ehNe8" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 BCED112CDB0 for ; Thu, 4 Apr 2024 14:07:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712239671; cv=none; b=b++EPxZeNDE1AEXtv7Y8idgkaGvO2nFXAsLbUWf0iWc/AEgXgAxMBLZPuqYEEae0iw+xjmAx4TX6xiuib1qLCL09+01YxePZuqnGVt+3ZY7SUHGWQRKP3Dr80y+h667Mm+G2GQHGrcQSgqsCny0F7zd8pBWPf27BbLr7k9/cQug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712239671; c=relaxed/simple; bh=tykj5BdnbBhEDoTqqhcWUzRiGTAAmqbSFh3K0DqcGjc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=RuUQb2epHXZGzQhkmZi2+f3KvsTpSrrmp7NIpZfkvkS3lDh9aEvz3h+QL7/UC47DqjXqkBo+VZAWTjYnscw3v9VpPeUwl9R4rBXA4R9HhTXQOJtFrpm+Ful+Sfmjg7Q7OYnwU9f+4K6b82gg0IaSD9g7/CzF2PE3x+CyRmupy8M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ty8ehNe8; arc=none smtp.client-ip=198.175.65.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712239669; x=1743775669; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tykj5BdnbBhEDoTqqhcWUzRiGTAAmqbSFh3K0DqcGjc=; b=Ty8ehNe82cs3JdSh2GsM9kjirjLEj7NCVtGPiLKBF88jpu45CF7oI95h txmrSFr9lIgkWe5+7xTJpW5gKR6S49zf35mWJkFPqN1rZtunJkXDjkZpV nFTNsM0cKI2cXGz+8viJHmt4jeEFRNF/CdS1H4DIUY8/RPIzeSsvlFE9W Bph6Jpa+3SKPG6CxUsCymqcBqJPJAPaJrkc9bJwAHwKql3waUUAMRV+Y1 AEtI4Fhc3xcBjawUpcygrdSbq/GVL3gowhGLshWe9HkYujVnoFcnlTzYu OEbZFWDUzCjOFkVsaEp9JdaXBTogLSfOpJLeGZSdLoiU4C0xbC+25OkVY Q==; X-CSE-ConnectionGUID: 8OehAmNZRVi7eqGjLdYaqQ== X-CSE-MsgGUID: Gv8iHljzTsar7nS9LjePAw== X-IronPort-AV: E=McAfee;i="6600,9927,11034"; a="11346554" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="11346554" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 07:07:49 -0700 X-CSE-ConnectionGUID: OWEJN3quSOeTB1c0CqdwQQ== X-CSE-MsgGUID: akytula2TNy7hjbabeKDKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="23258909" Received: from kanliang-dev.jf.intel.com ([10.165.154.102]) by fmviesa005.fm.intel.com with ESMTP; 04 Apr 2024 07:07:49 -0700 From: kan.liang@linux.intel.com To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org Cc: ak@linux.intel.com, Kan Liang Subject: [PATCH 09/12] perf: Extend perf_output_read Date: Thu, 4 Apr 2024 07:06:34 -0700 Message-Id: <20240404140637.1232635-10-kan.liang@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20240404140637.1232635-1-kan.liang@linux.intel.com> References: <20240404140637.1232635-1-kan.liang@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Kan Liang The event may have been updated in the PMU-specific implementation, e.g., Intel PEBS counters snapshotting. The common code should not read and overwrite the value. The PERF_SAMPLE_READ in the data->sample_type can be used to detect whether the PMU-specific value is available. If yes, avoid the pmu->read() in the common code. Reviewed-by: Andi Kleen Signed-off-by: Kan Liang --- kernel/events/core.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 724e6d7e128f..3bf305d866ab 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7219,7 +7219,7 @@ static void perf_output_read_one(struct perf_output_handle *handle, static void perf_output_read_group(struct perf_output_handle *handle, struct perf_event *event, - u64 enabled, u64 running) + u64 enabled, u64 running, bool read) { struct perf_event *leader = event->group_leader, *sub; u64 read_format = event->attr.read_format; @@ -7241,7 +7241,7 @@ static void perf_output_read_group(struct perf_output_handle *handle, if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) values[n++] = running; - if ((leader != event) && + if ((leader != event) && read && (leader->state == PERF_EVENT_STATE_ACTIVE)) leader->pmu->read(leader); @@ -7256,7 +7256,7 @@ static void perf_output_read_group(struct perf_output_handle *handle, for_each_sibling_event(sub, leader) { n = 0; - if ((sub != event) && + if ((sub != event) && read && (sub->state == PERF_EVENT_STATE_ACTIVE)) sub->pmu->read(sub); @@ -7283,7 +7283,8 @@ static void perf_output_read_group(struct perf_output_handle *handle, * on another CPU, from interrupt/NMI context. */ static void perf_output_read(struct perf_output_handle *handle, - struct perf_event *event) + struct perf_event *event, + bool read) { u64 enabled = 0, running = 0, now; u64 read_format = event->attr.read_format; @@ -7301,7 +7302,7 @@ static void perf_output_read(struct perf_output_handle *handle, calc_timer_values(event, &now, &enabled, &running); if (event->attr.read_format & PERF_FORMAT_GROUP) - perf_output_read_group(handle, event, enabled, running); + perf_output_read_group(handle, event, enabled, running, read); else perf_output_read_one(handle, event, enabled, running); } @@ -7343,7 +7344,7 @@ void perf_output_sample(struct perf_output_handle *handle, perf_output_put(handle, data->period); if (sample_type & PERF_SAMPLE_READ) - perf_output_read(handle, event); + perf_output_read(handle, event, !(data->sample_flags & PERF_SAMPLE_READ)); if (sample_type & PERF_SAMPLE_CALLCHAIN) { int size = 1; @@ -7944,7 +7945,7 @@ perf_event_read_event(struct perf_event *event, return; perf_output_put(&handle, read_event); - perf_output_read(&handle, event); + perf_output_read(&handle, event, true); perf_event__output_id_sample(event, &handle, &sample); perf_output_end(&handle); -- 2.35.1