Skip to content

Commit f133ecc

Browse files
arch/tile: more /proc and /sys file support
This change introduces a few of the less controversial /proc and /proc/sys interfaces for tile, along with sysfs attributes for various things that were originally proposed as /proc/tile files. It also adjusts the "hardwall" proc API. Arnd Bergmann reviewed the initial arch/tile submission, which included a complete set of all the /proc/tile and /proc/sys/tile knobs that we had added in a somewhat ad hoc way during initial development, and provided feedback on where most of them should go. One knob turned out to be similar enough to the existing /proc/sys/debug/exception-trace that it was re-implemented to use that model instead. Another knob was /proc/tile/grid, which reported the "grid" dimensions of a tile chip (e.g. 8x8 processors = 64-core chip). Arnd suggested looking at sysfs for that, so this change moves that information to a pair of sysfs attributes (chip_width and chip_height) in the /sys/devices/system/cpu directory. We also put the "chip_serial" and "chip_revision" information from our old /proc/tile/board file as attributes in /sys/devices/system/cpu. Other information collected via hypervisor APIs is now placed in /sys/hypervisor. We create a /sys/hypervisor/type file (holding the constant string "tilera") to be parallel with the Xen use of /sys/hypervisor/type holding "xen". We create three top-level files, "version" (the hypervisor's own version), "config_version" (the version of the configuration file), and "hvconfig" (the contents of the configuration file). The remaining information from our old /proc/tile/board and /proc/tile/switch files becomes an attribute group appearing under /sys/hypervisor/board/. Finally, after some feedback from Arnd Bergmann for the previous version of this patch, the /proc/tile/hardwall file is split up into two conceptual parts. First, a directory /proc/tile/hardwall/ which contains one file per active hardwall, each file named after the hardwall's ID and holding a cpulist that says which cpus are enclosed by the hardwall. Second, a /proc/PID file "hardwall" that is either empty (for non-hardwall-using processes) or contains the hardwall ID. Finally, this change pushes the /proc/sys/tile/unaligned_fixup/ directory, with knobs controlling the kernel code for handling the fixup of unaligned exceptions. Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
1 parent 7a0287d commit f133ecc

7 files changed

Lines changed: 347 additions & 28 deletions

File tree

‎arch/tile/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ config TILE
1212
select GENERIC_IRQ_PROBE
1313
select GENERIC_PENDING_IRQ if SMP
1414
select GENERIC_IRQ_SHOW
15+
select SYS_HYPERVISOR
1516

1617
# FIXME: investigate whether we need/want these options.
1718
# select HAVE_IOREMAP_PROT

‎arch/tile/include/asm/hardwall.h‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@
4040
#define HARDWALL_DEACTIVATE \
4141
_IO(HARDWALL_IOCTL_BASE, _HARDWALL_DEACTIVATE)
4242

43+
#define _HARDWALL_GET_ID 4
44+
#define HARDWALL_GET_ID \
45+
_IO(HARDWALL_IOCTL_BASE, _HARDWALL_GET_ID)
46+
4347
#ifndef __KERNEL__
4448

4549
/* This is the canonical name expected by userspace. */
4650
#define HARDWALL_FILE "/dev/hardwall"
4751

4852
#else
4953

50-
/* Hook for /proc/tile/hardwall. */
51-
struct seq_file;
52-
int proc_tile_hardwall_show(struct seq_file *sf, void *v);
54+
/* /proc hooks for hardwall. */
55+
struct proc_dir_entry;
56+
#ifdef CONFIG_HARDWALL
57+
void proc_tile_hardwall_init(struct proc_dir_entry *root);
58+
int proc_pid_hardwall(struct task_struct *task, char *buffer);
59+
#else
60+
static inline void proc_tile_hardwall_init(struct proc_dir_entry *root) {}
61+
#endif
5362

5463
#endif
5564

‎arch/tile/kernel/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
extra-y := vmlinux.lds head_$(BITS).o
66
obj-y := backtrace.o entry.o init_task.o irq.o messaging.o \
77
pci-dma.o proc.o process.o ptrace.o reboot.o \
8-
setup.o signal.o single_step.o stack.o sys.o time.o traps.o \
8+
setup.o signal.o single_step.o stack.o sys.o sysfs.o time.o traps.o \
99
intvec_$(BITS).o regs_$(BITS).o tile-desc_$(BITS).o
1010

1111
obj-$(CONFIG_HARDWALL) += hardwall.o

‎arch/tile/kernel/hardwall.c‎

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,25 @@
4040
struct hardwall_info {
4141
struct list_head list; /* "rectangles" list */
4242
struct list_head task_head; /* head of tasks in this hardwall */
43+
struct cpumask cpumask; /* cpus in the rectangle */
4344
int ulhc_x; /* upper left hand corner x coord */
4445
int ulhc_y; /* upper left hand corner y coord */
4546
int width; /* rectangle width */
4647
int height; /* rectangle height */
48+
int id; /* integer id for this hardwall */
4749
int teardown_in_progress; /* are we tearing this one down? */
4850
};
4951

5052
/* Currently allocated hardwall rectangles */
5153
static LIST_HEAD(rectangles);
5254

55+
/* /proc/tile/hardwall */
56+
static struct proc_dir_entry *hardwall_proc_dir;
57+
58+
/* Functions to manage files in /proc/tile/hardwall. */
59+
static void hardwall_add_proc(struct hardwall_info *rect);
60+
static void hardwall_remove_proc(struct hardwall_info *rect);
61+
5362
/*
5463
* Guard changes to the hardwall data structures.
5564
* This could be finer grained (e.g. one lock for the list of hardwall
@@ -105,6 +114,8 @@ static int setup_rectangle(struct hardwall_info *r, struct cpumask *mask)
105114
r->ulhc_y = cpu_y(ulhc);
106115
r->width = cpu_x(lrhc) - r->ulhc_x + 1;
107116
r->height = cpu_y(lrhc) - r->ulhc_y + 1;
117+
cpumask_copy(&r->cpumask, mask);
118+
r->id = ulhc; /* The ulhc cpu id can be the hardwall id. */
108119

109120
/* Width and height must be positive */
110121
if (r->width <= 0 || r->height <= 0)
@@ -388,6 +399,9 @@ static struct hardwall_info *hardwall_create(
388399
/* Set up appropriate hardwalling on all affected cpus. */
389400
hardwall_setup(rect);
390401

402+
/* Create a /proc/tile/hardwall entry. */
403+
hardwall_add_proc(rect);
404+
391405
return rect;
392406
}
393407

@@ -645,6 +659,9 @@ static void hardwall_destroy(struct hardwall_info *rect)
645659
/* Restart switch and disable firewall. */
646660
on_each_cpu_mask(&mask, restart_udn_switch, NULL, 1);
647661

662+
/* Remove the /proc/tile/hardwall entry. */
663+
hardwall_remove_proc(rect);
664+
648665
/* Now free the rectangle from the list. */
649666
spin_lock_irqsave(&hardwall_lock, flags);
650667
BUG_ON(!list_empty(&rect->task_head));
@@ -654,35 +671,57 @@ static void hardwall_destroy(struct hardwall_info *rect)
654671
}
655672

656673

657-
/*
658-
* Dump hardwall state via /proc; initialized in arch/tile/sys/proc.c.
659-
*/
660-
int proc_tile_hardwall_show(struct seq_file *sf, void *v)
674+
static int hardwall_proc_show(struct seq_file *sf, void *v)
661675
{
662-
struct hardwall_info *r;
676+
struct hardwall_info *rect = sf->private;
677+
char buf[256];
663678

664-
if (udn_disabled) {
665-
seq_printf(sf, "%dx%d 0,0 pids:\n", smp_width, smp_height);
666-
return 0;
667-
}
668-
669-
spin_lock_irq(&hardwall_lock);
670-
list_for_each_entry(r, &rectangles, list) {
671-
struct task_struct *p;
672-
seq_printf(sf, "%dx%d %d,%d pids:",
673-
r->width, r->height, r->ulhc_x, r->ulhc_y);
674-
list_for_each_entry(p, &r->task_head, thread.hardwall_list) {
675-
unsigned int cpu = cpumask_first(&p->cpus_allowed);
676-
unsigned int x = cpu % smp_width;
677-
unsigned int y = cpu / smp_width;
678-
seq_printf(sf, " %d@%d,%d", p->pid, x, y);
679-
}
680-
seq_printf(sf, "\n");
681-
}
682-
spin_unlock_irq(&hardwall_lock);
679+
int rc = cpulist_scnprintf(buf, sizeof(buf), &rect->cpumask);
680+
buf[rc++] = '\n';
681+
seq_write(sf, buf, rc);
683682
return 0;
684683
}
685684

685+
static int hardwall_proc_open(struct inode *inode,
686+
struct file *file)
687+
{
688+
return single_open(file, hardwall_proc_show, PDE(inode)->data);
689+
}
690+
691+
static const struct file_operations hardwall_proc_fops = {
692+
.open = hardwall_proc_open,
693+
.read = seq_read,
694+
.llseek = seq_lseek,
695+
.release = single_release,
696+
};
697+
698+
static void hardwall_add_proc(struct hardwall_info *rect)
699+
{
700+
char buf[64];
701+
snprintf(buf, sizeof(buf), "%d", rect->id);
702+
proc_create_data(buf, 0444, hardwall_proc_dir,
703+
&hardwall_proc_fops, rect);
704+
}
705+
706+
static void hardwall_remove_proc(struct hardwall_info *rect)
707+
{
708+
char buf[64];
709+
snprintf(buf, sizeof(buf), "%d", rect->id);
710+
remove_proc_entry(buf, hardwall_proc_dir);
711+
}
712+
713+
int proc_pid_hardwall(struct task_struct *task, char *buffer)
714+
{
715+
struct hardwall_info *rect = task->thread.hardwall;
716+
return rect ? sprintf(buffer, "%d\n", rect->id) : 0;
717+
}
718+
719+
void proc_tile_hardwall_init(struct proc_dir_entry *root)
720+
{
721+
if (!udn_disabled)
722+
hardwall_proc_dir = proc_mkdir("hardwall", root);
723+
}
724+
686725

687726
/*
688727
* Character device support via ioctl/close.
@@ -716,6 +755,9 @@ static long hardwall_ioctl(struct file *file, unsigned int a, unsigned long b)
716755
return -EINVAL;
717756
return hardwall_deactivate(current);
718757

758+
case _HARDWALL_GET_ID:
759+
return rect ? rect->id : -EINVAL;
760+
719761
default:
720762
return -EINVAL;
721763
}

‎arch/tile/kernel/proc.c‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <asm/processor.h>
2828
#include <asm/sections.h>
2929
#include <asm/homecache.h>
30+
#include <asm/hardwall.h>
3031
#include <arch/chip.h>
3132

3233

@@ -88,3 +89,75 @@ const struct seq_operations cpuinfo_op = {
8889
.stop = c_stop,
8990
.show = show_cpuinfo,
9091
};
92+
93+
/*
94+
* Support /proc/tile directory
95+
*/
96+
97+
static int __init proc_tile_init(void)
98+
{
99+
struct proc_dir_entry *root = proc_mkdir("tile", NULL);
100+
if (root == NULL)
101+
return 0;
102+
103+
proc_tile_hardwall_init(root);
104+
105+
return 0;
106+
}
107+
108+
arch_initcall(proc_tile_init);
109+
110+
/*
111+
* Support /proc/sys/tile directory
112+
*/
113+
114+
#ifndef __tilegx__ /* FIXME: GX: no support for unaligned access yet */
115+
static ctl_table unaligned_subtable[] = {
116+
{
117+
.procname = "enabled",
118+
.data = &unaligned_fixup,
119+
.maxlen = sizeof(int),
120+
.mode = 0644,
121+
.proc_handler = &proc_dointvec
122+
},
123+
{
124+
.procname = "printk",
125+
.data = &unaligned_printk,
126+
.maxlen = sizeof(int),
127+
.mode = 0644,
128+
.proc_handler = &proc_dointvec
129+
},
130+
{
131+
.procname = "count",
132+
.data = &unaligned_fixup_count,
133+
.maxlen = sizeof(int),
134+
.mode = 0644,
135+
.proc_handler = &proc_dointvec
136+
},
137+
{}
138+
};
139+
140+
static ctl_table unaligned_table[] = {
141+
{
142+
.procname = "unaligned_fixup",
143+
.mode = 0555,
144+
.child = unaligned_subtable
145+
},
146+
{}
147+
};
148+
#endif
149+
150+
static struct ctl_path tile_path[] = {
151+
{ .procname = "tile" },
152+
{ }
153+
};
154+
155+
static int __init proc_sys_tile_init(void)
156+
{
157+
#ifndef __tilegx__ /* FIXME: GX: no support for unaligned access yet */
158+
register_sysctl_paths(tile_path, unaligned_table);
159+
#endif
160+
return 0;
161+
}
162+
163+
arch_initcall(proc_sys_tile_init);

0 commit comments

Comments
 (0)