Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5647374ybg; Tue, 22 Oct 2019 06:27:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxLAERMxEtk4VK/IpyRGVRzTdJkI/2ku8p6rRwF3tyD9kzqhttce1O0L0hNXp5YrrUf3B+ X-Received: by 2002:a50:f384:: with SMTP id g4mr30696785edm.282.1571750828147; Tue, 22 Oct 2019 06:27:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571750828; cv=none; d=google.com; s=arc-20160816; b=P1eQXBl+NxHW0rf3OwYhfFx6QvW7fHmfaHr4NrJopYCcAL+l479UPjdowCJ0CQiF77 l5aBOIf8qhNuYFoPOn5z3g4g2M1meOXPVJDx4AdEcpqM/D153cHDzsLIPPIRK26htPTU V1Llxy3O2UR3o8hkEN6ywcDa7X+lFwhd5EpmfpXRT8cHSp3KrJwBJdeN2bRcqaHa4NYO +856KJGhVoGibmSDQAsQBK6GdiaZbXng0u81x8N4DWUCy8+VEjuahHujC/Z07IeTk8UO PCmU+YsxK0ysdAwSTF6Ap88JW8XMuAJF0E2YIcJztfsiXx8s4FVbFmTBHlhEdYNJiBr9 5DHg== 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:organization:from:references:cc:to:subject; bh=sz4nrV9yEtpSPyemEyzVHTp3Apc2UWh9tzmYYVe0iGE=; b=ll3iE5QGj4FQUd22XhNvFVfMX5KpfNqIFHOvfwyV9fyMkPgsR1U2jRNJKy/5a/vNOU Bad9x2TPxD4UxFZFyd3u8kuNGZTRq45BhzDzVQHbKVNiwj17pls3DgISOE5UyBq3BoRP 98MsPGDOCiERIgMHMvMT6Kjuy5fBoqByqj4fPZCuwcGDGIc08Glz+MekkOHEZzX6zikt Iq/M2oySStzwQ5vLL9MowZ7Y+dLA7yG0Hkviv1wlVk2y53wJyoZNELqpOp0ZbDaajMeN PRuN2CowZi3QRucKwpuIp2KjhaH5TuwlxUSuZXZ+6pwkyX0qicd8GHCIQokwbULyhrz+ uNmg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f21si3216686edf.277.2019.10.22.06.26.43; Tue, 22 Oct 2019 06:27:08 -0700 (PDT) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388760AbfJVLkK (ORCPT + 99 others); Tue, 22 Oct 2019 07:40:10 -0400 Received: from mga01.intel.com ([192.55.52.88]:6512 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387965AbfJVLkJ (ORCPT ); Tue, 22 Oct 2019 07:40:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Oct 2019 04:40:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,326,1566889200"; d="scan'208";a="349030713" Received: from linux.intel.com ([10.54.29.200]) by orsmga004.jf.intel.com with ESMTP; 22 Oct 2019 04:40:09 -0700 Received: from [10.125.253.19] (abudanko-mobl.ccr.corp.intel.com [10.125.253.19]) by linux.intel.com (Postfix) with ESMTP id 7508758048F; Tue, 22 Oct 2019 04:40:06 -0700 (PDT) Subject: Re: [PATCH v4 4/4] perf/core,x86: synchronize PMU task contexts on optimized context switches To: Peter Zijlstra Cc: Arnaldo Carvalho de Melo , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Andi Kleen , Kan Liang , Stephane Eranian , Ian Rogers , Song Liu , linux-kernel References: <4d6320bb-0d15-0028-aefb-a176c986b8db@linux.intel.com> <20191022094300.GL1817@hirez.programming.kicks-ass.net> From: Alexey Budankov Organization: Intel Corp. Message-ID: <50f1e2d5-3960-015c-c7e3-e850a17207ef@linux.intel.com> Date: Tue, 22 Oct 2019 14:40:05 +0300 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20191022094300.GL1817@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 22.10.2019 12:43, Peter Zijlstra wrote: > On Tue, Oct 22, 2019 at 09:01:11AM +0300, Alexey Budankov wrote: > >> swap(ctx->task_ctx_data, next_ctx->task_ctx_data); >> >> + /* >> + * PMU specific parts of task perf context can require >> + * additional synchronization which makes sense only if >> + * both next_ctx->task_ctx_data and ctx->task_ctx_data >> + * pointers are allocated. As an example of such >> + * synchronization see implementation details of Intel >> + * LBR call stack data profiling; >> + */ >> + if (ctx->task_ctx_data && next_ctx->task_ctx_data) >> + pmu->sync_task_ctx(next_ctx->task_ctx_data, >> + ctx->task_ctx_data); > > This still does not check if pmu->sync_task_ctx is set. If any other > arch ever uses task_ctx_data without then also supplying this method > things will go *bang*. Argh, and that is why it is documented as the optional one. Undoubtedly, we have to avoid crashes on other architectures. So "if (pmu->sync_task_ctx)" has to be a part of v5. > > Also, I think I prefer the variant I gave you yesterday: > > https://lkml.kernel.org/r/20191021103745.GF1800@hirez.programming.kicks-ass.net > > if (pmu->swap_task_ctx) > pmu->swap_task_ctx(ctx, next_ctx); > else > swap(ctx->task_ctx_data, next_ctx->task_ctx_data); > > That also unconfuses the argument order in your above patch (where you > have to undo thw swap). I would name the method sync_task_ctx not swap_task_ctx because sync reserves broader meaning, IMHO. ~Alexey