From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A08133F5BA for ; Mon, 11 May 2026 16:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778516266; cv=none; b=dMzE60J580GUEkTFCgTkux6hp7Nlwah70Z9YsGeVm8ZWuGcHHU8yd65iI624w/siYOK/JUyTYaVQWAe6RD1e/w5yW5pkZUdwEy7gIRiJSfsKVIdRYxYVAV6pMiV9zBADu32zxsY1Z3gNaYHmadf8gj8JwYtMCnb+wnkIytY+bnk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778516266; c=relaxed/simple; bh=0ara9K7QdBKThaPril0a4YvO62DrR2+YYX2Gg4rGizw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nu/jmE5insL7EO8Tg6sKR3Xsg07E34SLE/2NHHdWxc/tXQhFtqTWq1WkxJTswtPwoj7zdxz8oNK8wbRBy9ytH8/IDHwEKm1QNa8SeA3r5E9aj/ZWCxRgsQn3zKE/qzc9Ntyuu4ipwa7hjA3iH1IRv2RKac17aM+GiV+I/uFwz/g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=h+SEGZuG; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="h+SEGZuG" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-488af96f6b2so53701895e9.0 for ; Mon, 11 May 2026 09:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1778516263; x=1779121063; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=Bv+QO3gNHsfEC1WrzTCG9lEyRXfEmVBCtTyB0LNuW38=; b=h+SEGZuGPnT4f6kuY4LsnDaF8v7K7kR2bho0rinTzKRCdldzjHkg+ZAQssrZBFOFf8 GFq48hXRqpYmQlrLBeE8I2UBFJFTwGu0dQpJ8D/RwxM3/o4hSGQLR/cZcMImAQGfx3Qn cPSEh1HOjCyt6wjdQgouuKni2iIau5yQAaBHhWjzdj3pWgBWoJ9fA1A0TsWi1CdJhPWm Xl6m4ij7MYNJyaCcFLoJDn7DP98b7Qx+CyR5ipYY+yqWRxQ2hxx25QM0/zLHaIvipqvI M08Y9jBILwBlLFPXrfMlc8pCitJBu0XhUXxz6b3AAmy8uGcV7oa1Bde0G1auq1irHMbT k6CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778516263; x=1779121063; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Bv+QO3gNHsfEC1WrzTCG9lEyRXfEmVBCtTyB0LNuW38=; b=DjNSRVCtgrR9eFvltau6yszSxLv/OC1J4CqpjFKzBes6MlxfJIXqb1a4e4laEhaPY/ jvv6nHWDW7kvzCMM+3x4m2IIvKqiCzB8Nm3Z5WLnsj4H1gEg8hEqNyeRITLaw6dlr1iR tkc5ynBJVlFtuYZMwMKhCJZiZbnisBB9LX+Ynr5hwiYkS+6yiSPKME3iXAJst9uRwKnm x+HRoY5gabPAR8XFs8i/tSXoo5tg52ZgQlXcDI+zRMPoSJVgQweH7GaX0tT2JXXbAdk5 nIrvSiVPiPKzV+QS0XYATDM2VIuwzLIF/0sZyzljNrPdzdO2MLNWJ1lzMl7knC9Avplf qohw== X-Forwarded-Encrypted: i=1; AFNElJ9DnWnDV2bHKffJYeeA0uk5a7D9N2jSJiowRsMjU5ezyvvp022LoIbVNNK3vv2Qtq5AKZn+SJnEL4gAG7M=@vger.kernel.org X-Gm-Message-State: AOJu0YxQ/Eo/4K5VCx8Ir9jUPcjZis4CFjQ71oHl6VLTYEz/7sbYb66k 8AS/Rxj6j6HkaArZCEyUK7QF7SxTczaoO13H7c03PRe7w43ZqGMOu+8syas3BncvcHJrb4jDnpw 1OB9H0aU= X-Gm-Gg: Acq92OGfPBI1IaS5OTWnZT1JTQILJQ1k0SPmtUdFHB+E/wsy32MP4oroDhlV+nkord8 rmvxguXT2iQBm6KBX/bUUQkE+B74t1u/zw/V4fHpKm5ZPJw+67P5JM6GSpP4yk5nFSBXdzgTdAl 7qleo00hrgGKx32PrU1mHUbKT1zmxhOQI+htrdeCer+NQJCTSlu4Y9cudCEkP53JUn13xKoGo4o JxvalcqbRvZqkbhiqjFXG6cDC9Pz1kJXxJhdFoD/BNqoQAdR2KIyvkrNajXzPEXnqR+vEk0N4VS BU/9i+rq7+Qyat/DxzZ2sZn9gxRg9p22qZGe4vM0r+NRc856X2I14a4WEbxpQzx1q9ieBkN0Tgr 1cVXGGOpuQ8tc8ATu16FREH8N62qkMNwmCNmVQOYd/NoiQgvK8Vqi18aJIZ76+B9SwAdRMdqF2C Ei9M3sq+TAz0Kl4sBLPhexLL1VTLyiKT2o6428ZbM= X-Received: by 2002:a05:600c:35d6:b0:489:1ff1:74d3 with SMTP id 5b1f17b1804b1-48e707033f0mr174096475e9.20.1778516263522; Mon, 11 May 2026 09:17:43 -0700 (PDT) Received: from [192.168.1.3] ([185.48.77.170]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8e566cf7sm475125e9.0.2026.05.11.09.17.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 May 2026 09:17:43 -0700 (PDT) Message-ID: <970c4dd6-a2e6-4be7-afb3-63858d4d1f69@linaro.org> Date: Mon, 11 May 2026 17:17:42 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] perf test: Make leafloop workload immune to compiler options To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org References: <20260511-james-perf-leafloop-stack-v2-1-79f7383f545e@linaro.org> Content-Language: en-US From: James Clark In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/05/2026 4:38 pm, Ian Rogers wrote: > On Mon, May 11, 2026 at 2:19 AM James Clark wrote: >> >> Since the leafloop test program was moved into the main Perf binary as a >> workload, it inherited the same compiler options as Perf. In this case >> the -fstack-protector option broke the assumption that simple leaf >> frames don't have a stack frame on Arm. This causes >> test_arm_callgraph_fp.sh to pass even if the stack isn't augmented with >> the link register, making the test useless. >> >> Fix it by rewriting the leaf function in assembly seeing as it's so >> simple. Adding -fno-stack-protector would also work, but wouldn't be >> robust against other future compiler option additions. >> >> The local variables and 'a' variable were never needed so remove them to >> simplify. >> >> Assisted-by: GitHub-Copilot:GPT-5.5 >> Signed-off-by: James Clark >> --- >> Changes in v2: >> - Push and pop asm sections - (Sashiko) >> - Add .size directive - (Sashiko) >> - Add asm label for done and test with LTO enabled - (Sashiko) >> - Link to v1: https://lore.kernel.org/r/20260508-james-perf-leafloop-stack-v1-1-637c260b2da8@linaro.org >> --- >> tools/perf/tests/workloads/leafloop.c | 40 +++++++++++++++++++++++++++-------- >> 1 file changed, 31 insertions(+), 9 deletions(-) >> >> diff --git a/tools/perf/tests/workloads/leafloop.c b/tools/perf/tests/workloads/leafloop.c >> index f7561767e32c..c20c75f7ba49 100644 >> --- a/tools/perf/tests/workloads/leafloop.c >> +++ b/tools/perf/tests/workloads/leafloop.c >> @@ -6,26 +6,48 @@ >> #include "../tests.h" >> >> /* We want to check these symbols in perf script */ >> -noinline void leaf(volatile int b); >> -noinline void parent(volatile int b); >> +noinline void leaf(void); >> +noinline void parent(void); >> >> -static volatile int a; >> -static volatile sig_atomic_t done; >> +static volatile sig_atomic_t done asm("leafloop_done"); >> >> static void sighandler(int sig __maybe_unused) >> { >> done = 1; >> } >> >> -noinline void leaf(volatile int b) >> +#if defined(__aarch64__) >> +/* >> + * Write leaf() in assembly so it stays as a minimal leaf function with no >> + * stack frame and won't get silently broken in the future by any Perf wide >> + * compilation options like -fstack-protector-all. >> + */ >> +asm( >> + ".pushsection .text,\"ax\",%progbits\n" >> + ".global leaf\n" >> + ".type leaf, %function\n" >> + "leaf:\n" >> + " adrp x1, leafloop_done\n" >> + " ldr w2, [x1, #:lo12:leafloop_done]\n" >> + " cbz w2, leaf\n" >> + " ret\n" >> + ".size leaf, .-leaf\n" >> + ".popsection\n" >> +); > > On reading this I thought, why can't we just use an asm block in a > function, but I get it, you want specific function entry/exit to test > the leaf unwinding feature. > > Reviewed-by: Ian Rogers > > Fwiw, looking at the test the command line is somewhat unusual: > https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/tree/tools/perf/tests/shell/test_arm_callgraph_fp.sh?h=perf-tools-next#n32 > ``` > perf record -o "$PERF_DATA" --call-graph fp -e cycles//u > --user-callchains -- $TEST_PROGRAM > ``` > cycles//u rather than cycles:u and why the extra --user-callchains? > > Thanks, > Ian > --user-callchains looks like it was to make the grep in the test easier so it didn't have to ignore the kernel part. But it might be redundant now after a later change I made. cycles//u has always been there so there's no explanation. I thought that was a valid way to open an event? Is it weird because // is for options in perf record and not stat? >> + >> +#else >> + >> +noinline void leaf(void) >> { >> while (!done) >> - a += b; >> + ; >> } >> >> -noinline void parent(volatile int b) >> +#endif >> + >> +noinline void parent(void) >> { >> - leaf(b); >> + leaf(); >> } >> >> static int leafloop(int argc, const char **argv) >> @@ -39,7 +61,7 @@ static int leafloop(int argc, const char **argv) >> signal(SIGALRM, sighandler); >> alarm(sec); >> >> - parent(sec); >> + parent(); >> return 0; >> } >> >> >> --- >> base-commit: 8c8f2093614373ea8179b562320212a25cf937c0 >> change-id: 20260508-james-perf-leafloop-stack-c221600eddf2 >> >> Best regards, >> -- >> James Clark >>