From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754069AbcJENn2 (ORCPT ); Wed, 5 Oct 2016 09:43:28 -0400 Received: from out28-195.mail.aliyun.com ([115.124.28.195]:41633 "EHLO out28-195.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750807AbcJENn1 (ORCPT ); Wed, 5 Oct 2016 09:43:27 -0400 X-Greylist: delayed 305 seconds by postgrey-1.27 at vger.kernel.org; Wed, 05 Oct 2016 09:43:26 EDT X-Alimail-AntiSpam: AC=CONTINUE;BC=0.07445858|-1;FP=0|0|0|0|0|-1|-1|-1;HT=e02c03310;MF=chengang@emindsoft.com.cn;NM=1;PH=DS;RN=6;RT=5;SR=0;TI=SMTPD_---.7152Ltn_1475674688; From: chengang@emindsoft.com.cn To: akpm@linux-foundation.org, dhowells@redhat.com Cc: linux-kernel@vger.kernel.org, Chen Gang , Chen Gang Subject: [PATCH] uapi: linux: acct: Remove redundant type comp2_t from kernel Date: Wed, 5 Oct 2016 21:40:10 +0800 Message-Id: <1475674810-1560-1-git-send-email-chengang@emindsoft.com.cn> X-Mailer: git-send-email 1.9.3 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chen Gang In api itself, kernel does not use it -- it is divided into ac_etime_hi and ac_etime_lo. So kernel side only need generate the correct ac_etime_hi and ac_etime_lo, but need not know about comp2_t. At present, kernel use normal u64 type for it, when kernel provdes it to outside, kernel can translate it into ac_etime_hi and ac_etime_lo, directly, but need not notice about comp2_t, in fact. The patch notices about coding styles: - Use 1 instead of 1ul, since type int is enough. - Use white space between operator and constant or macro. - Initialize variables directly, when declare it, since they need be initialized and can be initialized by constant (include constant macros). - Remove redundant empty line. Signed-off-by: Chen Gang --- include/uapi/linux/acct.h | 6 ++++-- kernel/acct.c | 31 ++++++++++++++----------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/uapi/linux/acct.h b/include/uapi/linux/acct.h index df2f9a0..97acdd4 100644 --- a/include/uapi/linux/acct.h +++ b/include/uapi/linux/acct.h @@ -24,12 +24,15 @@ * comp_t is a 16-bit "floating" point number with a 3-bit base 8 * exponent and a 13-bit fraction. * comp2_t is 24-bit with 5-bit base 2 exponent and 20 bit fraction - * (leading 1 not stored). + * (leading 1 not stored). And it is described as ac_etime_hi and + * ac_etime_lo in kernel. * See linux/kernel/acct.c for the specific encoding systems used. */ typedef __u16 comp_t; +#ifndef __KERNEL__ typedef __u32 comp2_t; +#endif /* __KERNEL */ /* * accounting file record @@ -120,5 +123,4 @@ struct acct_v3 #define AHZ (HZ) #endif /* __KERNEL */ - #endif /* _UAPI_LINUX_ACCT_H */ diff --git a/kernel/acct.c b/kernel/acct.c index 74963d1..f707a10 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -338,7 +338,7 @@ static comp_t encode_comp_t(unsigned long value) #if ACCT_VERSION == 1 || ACCT_VERSION == 2 /* - * encode an u64 into a comp2_t (24 bits) + * encode an u64 into ac_etime_hi and ac_etime_lo (24 bits) * * Format: 5 bit base 2 exponent, 20 bits mantissa. * The leading bit of the mantissa is not stored, but implied for @@ -348,15 +348,15 @@ static comp_t encode_comp_t(unsigned long value) #define MANTSIZE2 20 /* 20 bit mantissa. */ #define EXPSIZE2 5 /* 5 bit base 2 exponent. */ -#define MAXFRACT2 ((1ul << MANTSIZE2) - 1) /* Maximum fractional value. */ -#define MAXEXP2 ((1 << EXPSIZE2) - 1) /* Maximum exponent. */ +#define MAXFRACT2 ((1 << MANTSIZE2) - 1) /* Maximum fractional value. */ +#define MAXEXP2 ((1 << EXPSIZE2) - 1) /* Maximum exponent. */ -static comp2_t encode_comp2_t(u64 value) +static void encode_ac_etime_hilo(u64 value, acct_t *ac) { - int exp, rnd; + int exp = (value > (MAXFRACT2 >> 1)); + int rnd = 0; + u32 etime; - exp = (value > (MAXFRACT2>>1)); - rnd = 0; while (value > MAXFRACT2) { rnd = value & 1; value >>= 1; @@ -373,10 +373,12 @@ static comp2_t encode_comp2_t(u64 value) if (exp > MAXEXP2) { /* Overflow. Return largest representable number instead. */ - return (1ul << (MANTSIZE2+EXPSIZE2-1)) - 1; + etime = (1 << (MANTSIZE2 + EXPSIZE2 - 1)) - 1; } else { - return (value & (MAXFRACT2>>1)) | (exp << (MANTSIZE2-1)); + etime = (value & (MAXFRACT2 >> 1)) | (exp << (MANTSIZE2 - 1)); } + ac->ac_etime_hi = etime >> 16; + ac->ac_etime_lo = (u16) etime; } #endif @@ -436,17 +438,12 @@ static void fill_ac(acct_t *ac) (unsigned long) elapsed : (unsigned long) -1l); #endif #if ACCT_VERSION == 1 || ACCT_VERSION == 2 - { - /* new enlarged etime field */ - comp2_t etime = encode_comp2_t(elapsed); - - ac->ac_etime_hi = etime >> 16; - ac->ac_etime_lo = (u16) etime; - } + /* new enlarged etime field */ + encode_ac_etime_hilo(elapsed, ac); #endif do_div(elapsed, AHZ); ac->ac_btime = get_seconds() - elapsed; -#if ACCT_VERSION==2 +#if ACCT_VERSION == 2 ac->ac_ahz = AHZ; #endif -- 1.9.3