From patchwork Tue Feb 16 12:01:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: jamal X-Patchwork-Id: 45462 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id E1B27B7CC2 for ; Tue, 16 Feb 2010 23:01:31 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755434Ab0BPMB1 (ORCPT ); Tue, 16 Feb 2010 07:01:27 -0500 Received: from mail-qy0-f178.google.com ([209.85.221.178]:56103 "EHLO mail-qy0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754345Ab0BPMB0 (ORCPT ); Tue, 16 Feb 2010 07:01:26 -0500 Received: by qyk8 with SMTP id 8so859182qyk.24 for ; Tue, 16 Feb 2010 04:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:subject:from:reply-to :to:cc:content-type:date:message-id:mime-version:x-mailer; bh=R6lH6Co4SzmwDhbvOgJoWptHZqD+HhwCFUMRRAXU6S4=; b=MeCX8hLkeqtDvi82muVHQjO9nF81DHgcPUitF+0ztMQLIw80GCebhSCGL+haQf3tZW e6v21mcpdMFp6+tH4bLarZNmcV35EhlnlAGU7sG+idXAoZq8iIgSIlsUmuvhW2rc5uJi AZ22MMf5RrX5mQEiBIdXEtG7COcXR2FYPLWXo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:subject:from:reply-to:to:cc:content-type:date:message-id :mime-version:x-mailer; b=Xnmpa17pSPTkj1uVQyt6L5OcwPh9cC/yEufkyPNvEQW0wG6xujAClRb0xYycv3fKkK Q476/3MunKvo5+Vm/1GlhJqVrOGNatddMhBy1Bf9VYqNqySIlr4Mv0oI2Y+kOTHoKZji foNnfy3qdBCmKVt+RR3z0eqFIY+pNtPKY/3AQ= Received: by 10.224.80.17 with SMTP id r17mr753902qak.56.1266321683992; Tue, 16 Feb 2010 04:01:23 -0800 (PST) Received: from ?10.0.0.26? (CPE0030ab124d2f-CM001bd7a7f1a0.cpe.net.cable.rogers.com [99.240.66.42]) by mx.google.com with ESMTPS id 5sm21634145qwg.28.2010.02.16.04.01.22 (version=SSLv3 cipher=RC4-MD5); Tue, 16 Feb 2010 04:01:23 -0800 (PST) Subject: xfrm: avoid spinlock in get_acqseq() used by xfrm user From: jamal Reply-To: hadi@cyberus.ca To: David Miller Cc: Eric Dumazet , netdev@vger.kernel.org Date: Tue, 16 Feb 2010 07:01:22 -0500 Message-Id: <1266321682.6776.254.camel@bigi> Mime-Version: 1.0 X-Mailer: Evolution 2.26.1 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Eric's version fixed it for pfkey. This one is for xfrm user. I thought about amortizing those two get_acqseq()s but it seems reasonable to have two of these sequence spaces for the two different interfaces. cheers, jamal commit d5168d5addbc999c94aacda8f28a4a173756a72b Author: Jamal Hadi Salim Date: Tue Feb 16 06:51:22 2010 -0500 xfrm: avoid spinlock in get_acqseq() used by xfrm user This is in the same spirit as commit 28aecb9d7728dc26bf03ce7925fe622023a83a2a by Eric Dumazet. Use atomic_inc_return() in get_acqseq() to avoid taking a spinlock Signed-off-by: Jamal Hadi Salim Acked-by: Eric Dumazet diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c index f50ee9b..96f2088 100644 --- a/net/xfrm/xfrm_state.c +++ b/net/xfrm/xfrm_state.c @@ -1462,12 +1462,12 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq); u32 xfrm_get_acqseq(void) { u32 res; - static u32 acqseq; - static DEFINE_SPINLOCK(acqseq_lock); + static atomic_t acqseq; + + do { + res = atomic_inc_return(&acqseq); + } while (!res); - spin_lock_bh(&acqseq_lock); - res = (++acqseq ? : ++acqseq); - spin_unlock_bh(&acqseq_lock); return res; } EXPORT_SYMBOL(xfrm_get_acqseq);