Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3296847rwb; Mon, 3 Oct 2022 12:39:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7k2sXNMbpD9VMCzeBWM8Oss5PtSQ6bUVenlru+/MSIffWLzcCj2AHTDLjixo3RP7AqUpC8 X-Received: by 2002:a63:da12:0:b0:43a:18ce:f959 with SMTP id c18-20020a63da12000000b0043a18cef959mr19863779pgh.386.1664825966454; Mon, 03 Oct 2022 12:39:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664825966; cv=none; d=google.com; s=arc-20160816; b=Rc0LtAdOaBeTbKrLfjWFiTYGHBd9tLy3sjvD76mcDQNyh1QYPvCyDsuQNhsuBWzVlW vuZ/hdonvsncAC2E2lSG2sjYwJhysCIeWhEqXEfOCUqV7wAF+PmcKPJ/7pPRD7iJvC8g qWm2Ts5jlrzLXx6UIsX8IrwAoY41iu9Hwm2FntUMsmsVclGTz6pdofqb6wbkaBXafTQM lJPy3soeMastnsx8w/fyihZhM9huMjcdWVxWDw1HlYqRbPGSJmSIP1LB76n92YIZcVKi fWXc2Zpu5DSj1SG3RUBws/CzglGvZx4H2fSHPJjfupDNEpzmXMrL2n4KuaqbapCWxwWZ UEFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ME1oTRsKwcRu7pn4CZOREj68nEw1ojk/ZGR5xxUk3Sg=; b=wC1xv0L81bdurNBtsdSTd4j21X+LXGLYTxxLIW6QnQW+RABBRXTZTiO7RREfj55Ydd cS0Ks0H+nRMDKjettyh++XolGfxhS/gfGRRZeN/p0VxSWlWRe8qpdPviIUZ6bLdRBPYG GhbvDhApTmEenc6lYVCOR3/simJJxIURCFa5Mu4wW75+Z7hHI0kfSMLvabFu0Eg8FtQD DWbQDFIMuhvcNSViNtd4rk0pD5XHBMSQ0kSsE8tH60FuzhbHREhQRm3bloRHMnhJQBpE Fo3W2GQfGDEozkwDM8JqUK0mUae5jra1QDi4B+I2kuRA4ecQyej3ILp9rADVJQXw4iMt 9Dzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OH+1O0yB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h193-20020a636cca000000b0045417660b45si633230pgc.5.2022.10.03.12.39.09; Mon, 03 Oct 2022 12:39:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=OH+1O0yB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229673AbiJCTDZ (ORCPT + 99 others); Mon, 3 Oct 2022 15:03:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229577AbiJCTDX (ORCPT ); Mon, 3 Oct 2022 15:03:23 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7ACC92CE2C for ; Mon, 3 Oct 2022 12:03:21 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id s30so12202590eds.1 for ; Mon, 03 Oct 2022 12:03:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=ME1oTRsKwcRu7pn4CZOREj68nEw1ojk/ZGR5xxUk3Sg=; b=OH+1O0yBwvwn63HKW65OnVIOZQaonjRKJTCdSGeVuP5d1mzORL/by5EYWtrNl+DiRV H/iv0rwX4Akil6x2X/fNwZSzNVfEbtiYH/Jzfpn9rh63p7N90ximWOclhYH8YRQVsyJZ HxdKryNPruy7rMvoXh0wntcTdNLx/+mfL9Qx+H2a9HzTL092YWHBax3tds1GJkB7hnR8 0h0oCxEe0t6m5oQVNq1wrjs7KyGy7KA3pyI5HHRdpQyfZuKhxvu37VuDjQpP66u7H0Te vL9kneYYgcGNk8/hNOSCXy7A4bp4JOXViCuAoYJ3Isfp5+yUJQle0HOBrfhtsqWq25Vf 9qfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=ME1oTRsKwcRu7pn4CZOREj68nEw1ojk/ZGR5xxUk3Sg=; b=GUOn1qmU5XG+6KX5DDYyo+efeDR92yosJs4kX3CWA2YYewCBSFAIDCrw/fSiWLdosI d66Gh13vddA1WsuTnhUssHzOg48k1wHojyCZc8+0RmMgKMiK6vFTsUKmBbTAub5ztqMZ sWPw6Qcal6irF46GvQX53IUMve8HF2csJTIqyEse1tawjsuUkrKhu8OT+hbjVGL7+6VD 7NY3TmpgIXHjDQDllboangsZKv+8iIQJpqLSS29CJZmpSCG2vs5q7bVG5QKLN7Ig0Ja2 fRebTAoodBPQ+qFNK6ZLeP9CQSAjEuSn5m1Q7QCLGqxLUPqOyOv0rB0G4PiVqiWsqmMU hPag== X-Gm-Message-State: ACrzQf0rFW4amYpQdZJxcdcDYct9GMtbxH/wWsVxYW2QBomNe1dNdIcS Q4zTkjxD2NXi/Y4m1yZZK0h3EeGNh6NS9FandOa3dQ== X-Received: by 2002:a05:6402:540d:b0:450:bda7:f76e with SMTP id ev13-20020a056402540d00b00450bda7f76emr20009652edb.249.1664823799850; Mon, 03 Oct 2022 12:03:19 -0700 (PDT) MIME-Version: 1.0 References: <20220910212804.670622-1-davidgow@google.com> In-Reply-To: From: Daniel Latypov Date: Mon, 3 Oct 2022 12:03:08 -0700 Message-ID: Subject: Re: [RFC PATCH v2 0/2] kunit: Support redirecting function calls To: Joe Fradley Cc: David Gow , Brendan Higgins , Kees Cook , Shuah Khan , Steven Rostedt , Steve Muckle , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 30, 2022 at 8:59 AM Joe Fradley wrote: > Regarding the implementation, could there be more granualitary in the > activation of these stubs? Considering there's a small amount overhead > for these stubs when CONFIG_KUNIT is enabled, a developer's environment > could be adversely affected when they're testing a completely different > area that doesn't require mocks. > > Maybe only activate these with CONFIG_KUNIT_FTRACE_STUBS and > CONFIG_KUNIT_STATIC_STUBS respectively? Just to clarify, for ftrace, there shouldn't be overhead unless a stub is used. So it's not relevant for the following discussion. But for "static stubs", KUNIT_STATIC_STUB_REDIRECT() checks for current->kunit_test and kunit_find_resource() call to look for potential stubs. The current->kunit_test overhead should go away if we use a static key [1] instead to track if KUnit is running. David has a patch he's working on to do just that. So the overhead for Android when tests aren't running should mostly vanish. But there's still overhead when you *are* running tests. As you pointed out, all KUNIT_STATIC_STUB_REDIRECT() callsites will have overhead, even in functions you never intend to stub out. I.e. there's an O(n) scan of the resource list for potential stubs _for every single call_. We could add a CONFIG_KUNIT_STATIC_STUBS option and have KUNIT_STATIC_STUB_REDIRECT() be a no-op in that case. But if you have it turned on, then all the overhead comes back, even for functions you don't care to test. And given the goal is that this feature be useful and ubiquitous enough, that would be the steady state. I feel like we'd need to wait to see how this feature gets used to determine 1) if we should try and reduce the overhead 2) how we go about doing so (e.g. separate list for stubs, static keys, hash-based lookups of stubs, etc.) If people are mostly going to use ftrace, then this might not be worth trying to address. [1] https://docs.kernel.org/staging/static-keys.html Daniel