Re: [PATCH] arch/tile: add /proc/tile, /proc/sys/tile, and a sysfs cpu attribute

From: Arnd Bergmann
Date: Thu May 19 2011 - 09:41:25 EST


On Tuesday 17 May 2011, Chris Metcalf wrote:

> /proc/tile/hv
> Version information about the running Tilera hypervisor
>
> /proc/tile/hvconfig
> Detailed configuration description of the hypervisor config
>
> /proc/tile/board
> Information on part numbers, serial numbers, etc., of the
> hardware that the kernel is executing on
>
> /proc/tile/switch
> The type of control path for the onboard network switch, if any.
>
> /proc/tile/hardwall
> Information on the set of currently active hardwalls (note that
> the implementation is already present in arch/tile/kernel/hardwall.c;
> this change just enables it)

These all look like ideal candidates for sysfs attributes under
/sys/hypervisor, doing them one value per file, instead of grouping
them into multiple entries per file.

You can also turn each of these files into one directory under
/sys/hypervisor, with one or more files under it.

> diff --git a/arch/tile/kernel/sysfs.c b/arch/tile/kernel/sysfs.c
> new file mode 100644
> index 0000000..151deeb
> --- /dev/null
> +++ b/arch/tile/kernel/sysfs.c
> @@ -0,0 +1,52 @@
> +/*
> + * Copyright 2011 Tilera Corporation. All Rights Reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation, version 2.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
> + * NON INFRINGEMENT. See the GNU General Public License for
> + * more details.
> + *
> + * /sys entry support.
> + */
> +
> +#include <linux/sysdev.h>
> +#include <linux/cpu.h>
> +#include <linux/smp.h>
> +
> +static ssize_t chip_width_show(struct sysdev_class *dev,
> + struct sysdev_class_attribute *attr,
> + char *page)
> +{
> + return sprintf(page, "%u\n", smp_width);
> +}
> +static SYSDEV_CLASS_ATTR(chip_width, 0444, chip_width_show, NULL);
> +
> +static ssize_t chip_height_show(struct sysdev_class *dev,
> + struct sysdev_class_attribute *attr,
> + char *page)
> +{
> + return sprintf(page, "%u\n", smp_height);
> +}
> +static SYSDEV_CLASS_ATTR(chip_height, 0444, chip_height_show, NULL);
> +
> +
> +static int __init create_cpu_entries(void)
> +{
> + struct sysdev_class *cls = &cpu_sysdev_class;
> + int err = 0;
> +
> + if (!err)
> + err = sysfs_create_file(&cls->kset.kobj,
> + &attr_chip_width.attr);
> + if (!err)
> + err = sysfs_create_file(&cls->kset.kobj,
> + &attr_chip_height.attr);
> +
> + return err;
> +}

This should use sysdev_create_file instead of open-coding it.

Arnd

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/