[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xen Coding style and clang-format


  • To: Anastasiia Lukianenko <Anastasiia_Lukianenko@xxxxxxxx>
  • From: George Dunlap <George.Dunlap@xxxxxxxxxx>
  • Date: Mon, 12 Oct 2020 18:09:16 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mQtuHwexDo0BOb9pxNFmUuM+i03PpgjzgSLPCeutbVI=; b=kkxu7cjAlUAuOD0bjyDf8apBIu8Ik4uMmOLt8Ag9F8vIGVVUHj8AnY8gCvtkOTzmMI+oo30DPJXoomLgr4k//wzJX6Xmcb57qMVVHE9/OVXqPnl2umI12dfae9O5HtBCJ6wO8xygTL6EphpO6VpPA10m0tE4DXWEQkV1Yc8qKhvExWqtOcPChW4zzmEI7Tqkwj3oyYJUKGtAaTibmn2P2lcSxnjjUzK5SosBU5H2pJhaP4gdesiWRSAQC1rXAdyEUNLq4xFjfSxWJoqJXrXPSj4Sgng+wBclcWzKO0oc9k/f4G87fR4xldvPPlVJyKBWEIArUAMooDsiZUsFqbFrBw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hnugOpaBW8NRAgAWLOmQdxS4SRl+TBYU3Jkc3sIzeicU9+NqQlbdV/dNXX0tEjgHTcVgXi+QMvNAa7WBth7D/duBOxGRRdKx0Wtoa5E96Nzc+zGPTDxmQNqpz3qvvy6XpRGYHtqFf+tgVBtyA8svoQqoQrYQBTu8U6szmbHdyMpnOWq6BOfP0a7ZFii/ZZ2jACcUpi06MNaj4bx+UYHuh3Tl2xB1BgLZjJYUNQ9Ni3LBRUJnfUqq4UVauSPug2MParHhsxDkUONJq8Ej6olabzoV3Q+b4kXMVG0yjx9TnQg3BapN2mwnmp132t45ZHY8G4zlqkY0WJ/33JlSHv2AMA==
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "viktor.mitin.19@xxxxxxxxx" <viktor.mitin.19@xxxxxxxxx>, "vicooodin@xxxxxxxxx" <vicooodin@xxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, "Artem Mygaiev" <Artem_Mygaiev@xxxxxxxx>, "committers@xxxxxxxxxxxxxx" <committers@xxxxxxxxxxxxxx>, "jbeulich@xxxxxxxx" <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 12 Oct 2020 18:09:46 +0000
  • Ironport-sdr: AZKTaq3vzAG+tcfIc6utVleQaA9fejLxDWKWR1JR3FskM0RGm0K8PbII58GUqtNMVVmhdDmkm3 X2fOOfhEbDS6u7Ci5LDuCQIuQUVOe0bt4O/yvZcmZqWePrIYWrr0Awj3LihQ1+SdUO6RZ5QfCI ORQUTPWEsiS48AgpqZpZEhI5Mk1+O+IXMwM1SDuYwyX9V2Fg+OPpHnIOFd51ipBcfVBdZkOPpL 6VTC0LF4ioxS3nGmD1+VnYqYU7gsm9Zl3FM2LuK79mUnneTfNPyC3j7FGlUcnHiG0T0Yqs7pqp 6r4=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHWlwq4nKYEhMN38U+xmvwRsutq+amA8joAgAAHUgCAAXyKAIAAENkAgAlxpgCACF7sgA==
  • Thread-topic: Xen Coding style and clang-format


> On Oct 7, 2020, at 11:19 AM, Anastasiia Lukianenko 
> <Anastasiia_Lukianenko@xxxxxxxx> wrote:
> 
> Hi all,
> 
> On Thu, 2020-10-01 at 10:06 +0000, George Dunlap wrote:
>>> On Oct 1, 2020, at 10:06 AM, Anastasiia Lukianenko <
>>> Anastasiia_Lukianenko@xxxxxxxx> wrote:
>>> 
>>> Hi,
>>> 
>>> On Wed, 2020-09-30 at 10:24 +0000, George Dunlap wrote:
>>>>> On Sep 30, 2020, at 10:57 AM, Jan Beulich <jbeulich@xxxxxxxx>
>>>>> wrote:
>>>>> 
>>>>> On 30.09.2020 11:18, Anastasiia Lukianenko wrote:
>>>>>> I would like to know your opinion on the following coding
>>>>>> style
>>>>>> cases.
>>>>>> Which option do you think is correct?
>>>>>> 1) Function prototype when the string length is longer than
>>>>>> the
>>>>>> allowed
>>>>>> one
>>>>>> -static int __init
>>>>>> -acpi_parse_gic_cpu_interface(struct acpi_subtable_header
>>>>>> *header,
>>>>>> -                             const unsigned long end)
>>>>>> +static int __init acpi_parse_gic_cpu_interface(
>>>>>> +    struct acpi_subtable_header *header, const unsigned long
>>>>>> end)
>>>>> 
>>>>> Both variants are deemed valid style, I think (same also goes
>>>>> for
>>>>> function calls with this same problem). In fact you mix two
>>>>> different style aspects together (placement of parameter
>>>>> declarations and placement of return type etc) - for each
>>>>> individually both forms are deemed acceptable, I think.
>>>> 
>>>> If we’re going to have a tool go through and report (correct?)
>>>> all
>>>> these coding style things, it’s an opportunity to think if we
>>>> want to
>>>> add new coding style requirements (or change existing
>>>> requirements).
>>>> 
>>> 
>>> I am ready to discuss new requirements and implement them in rules
>>> of
>>> the Xen Coding style checker.
>> 
>> Thank you. :-)  But what I meant was: Right now we don’t require one
>> approach or the other for this specific instance.  Do we want to
>> choose one?
>> 
>> I think in this case it makes sense to do the easiest thing.  If it’s
>> easy to make the current tool accept both styles, let’s just do that
>> for now.  If the tool currently forces you to choose one of the two
>> styles, let’s choose one.
>> 
>> -George
> 
> During the detailed study of the Xen checker and the Clang-Format Style
> Options, it was found that this tool, unfortunately, is not so flexible
> to allow the author to independently choose the formatting style in
> situations that I described in the last letter. For example define code
> style:
> -#define ALLREGS \
> -    C(r0, r0_usr);   C(r1, r1_usr);   C(r2, r2_usr);   C(r3,
> r3_usr);   \
> -    C(cpsr, cpsr)
> +#define ALLREGS            \
> +    C(r0, r0_usr);         \
> +    C(r1, r1_usr);         \
> +    C(r2, r2_usr);         \
> There are also some inconsistencies in the formatting of the tool and
> what is written in the hyung coding style rules. For example, the
> comment format:
> -    /* PC should be always a multiple of 4, as Xen is using ARM
> instruction set */
> +    /* PC should be always a multiple of 4, as Xen is using ARM
> instruction set
> +     */
> I would like to draw your attention to the fact that the comment
> behaves in this way, since the line length exceeds the allowable one.
> The ReflowComments option is responsible for this format. It can be
> turned off, but then the result will be:
> ReflowComments=false:
> /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with
> plenty of information */
> 
> ReflowComments=true:
> /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with
> plenty of
> * information */
> 
> So I want to know if the community is ready to add new formatting
> options and edit old ones. Below I will give examples of what
> corrections the checker is currently making (the first variant in each
> case is existing code and the second variant is formatted by checker).
> If they fit the standards, then I can document them in the coding
> style. If not, then I try to configure the checker. But the idea is
> that we need to choose one option that will be considered correct.
> 1) Function prototype when the string length is longer than the allowed
> -static int __init
> -acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
> -                             const unsigned long end)
> +static int __init acpi_parse_gic_cpu_interface(
> +    struct acpi_subtable_header *header, const unsigned long end)

Jan already commented on this one; is there any way to tell the checker to 
ignore  this discrepancy?

If not, I think we should just choose one; I’d go with the latter.

> 2) Wrapping an operation to a new line when the string length is longer
> than the allowed
> -    status = acpi_get_table(ACPI_SIG_SPCR, 0,
> -                            (struct acpi_table_header **)&spcr);
> +    status =
> +        acpi_get_table(ACPI_SIG_SPCR, 0, (struct acpi_table_header
> **)&spcr);

Personally I prefer the first version.

> 3) Space after brackets
> -    return ((char *) base + offset);
> +    return ((char *)base + offset);

This seems like a good change to me.

> 4) Spaces in brackets in switch condition
> -    switch ( domctl->cmd )
> +    switch (domctl->cmd)

This is explicitly against the current coding style.

> 5) Spaces in brackets in operation
> -    imm = ( insn >> BRANCH_INSN_IMM_SHIFT ) & BRANCH_INSN_IMM_MASK;
> +    imm = (insn >> BRANCH_INSN_IMM_SHIFT) & BRANCH_INSN_IMM_MASK;

I *think* this is already the official style.

> 6) Spaces in brackets in return
> -        return ( !sym->name[2] || sym->name[2] == '.' );
> +        return (!sym->name[2] || sym->name[2] == '.');

Similarly, I think this is already the official style.

> 7) Space after sizeof
> -    clean_and_invalidate_dcache_va_range(new_ptr, sizeof (*new_ptr) *
> len);
> +    clean_and_invalidate_dcache_va_range(new_ptr, sizeof(*new_ptr) *
> len);

I think this is correct.

> 8) Spaces before comment if it’s on the same line
> -    case R_ARM_MOVT_ABS: /* S + A */
> +    case R_ARM_MOVT_ABS:    /* S + A */
> 
> -    if ( tmp == 0UL )       /* Are any bits set? */
> -        return result + size;   /* Nope. */
> +    if ( tmp == 0UL )         /* Are any bits set? */
> +        return result + size; /* Nope. */

Seem OK to me.

> 
> 9) Space after for_each_vcpu
> -        for_each_vcpu(d, v)
> +        for_each_vcpu (d, v)

Er, not sure about this one.  This is actually a macro; but obviously it looks 
like for ( ).

I think Jan will probably have an opinion, and I think he’ll be back tomorrow; 
so maybe wait just a day or two before starting to prep your series.

> 10) Spaces in declaration
> -    union hsr hsr = { .bits = regs->hsr };
> +    union hsr hsr = {.bits = regs->hsr};

I’m fine with this too.

 -George


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.