Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Feb 2023 07:33:58 GMT
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 889a9acc5475 - main - ipsec: only update lastused when it changes
Message-ID:  <202302160733.31G7Xww1084574@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=889a9acc54758922b3529ea473a2dac159d85fd5

commit 889a9acc54758922b3529ea473a2dac159d85fd5
Author:     Mateusz Guzik <mjg@FreeBSD.org>
AuthorDate: 2023-02-08 09:53:05 +0000
Commit:     Mateusz Guzik <mjg@FreeBSD.org>
CommitDate: 2023-02-16 07:33:51 +0000

    ipsec: only update lastused when it changes
    
    to limit cache-line bouncing.
    
    Note that as there is no atomic_store we are hoping the compiler wont
    speculatively do the store. It is not employed because the size depends
    on target arch.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D38433
---
 sys/netipsec/key.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/netipsec/key.c b/sys/netipsec/key.c
index 345c302c2a80..62aa99019437 100644
--- a/sys/netipsec/key.c
+++ b/sys/netipsec/key.c
@@ -917,6 +917,7 @@ key_allocsp(struct secpolicyindex *spidx, u_int dir)
 	struct spdcache_entry *entry, *lastentry, *tmpentry;
 	struct secpolicy *sp;
 	uint32_t hashv;
+	time_t ts;
 	int nb_entries;
 
 	if (!SPDCACHE_ACTIVE()) {
@@ -969,7 +970,9 @@ key_allocsp(struct secpolicyindex *spidx, u_int dir)
 
 out:
 	if (sp != NULL) {	/* found a SPD entry */
-		sp->lastused = time_second;
+		ts = time_second;
+		if (__predict_false(sp->lastused != ts))
+			sp->lastused = ts;
 		KEYDBG(IPSEC_STAMP,
 		    printf("%s: return SP(%p)\n", __func__, sp));
 		KEYDBG(IPSEC_DATA, kdebug_secpolicy(sp));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302160733.31G7Xww1084574>