2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2004-2005 Silicon Graphics, Inc. All rights reserved.
8 * SGI Altix topology and hardware performance monitoring API.
9 * Mark Goodwin <markgw@sgi.com>.
11 * Creates /proc/sgi_sn/sn_topology (read-only) to export
12 * info about Altix nodes, routers, CPUs and NumaLink
13 * interconnection/topology.
15 * Also creates a dynamic misc device named "sn_hwperf"
16 * that supports an ioctl interface to call down into SAL
17 * to discover hw objects, topology and to read/write
18 * memory mapped registers, e.g. for performance monitoring.
19 * The "sn_hwperf" device is registered only after the procfs
20 * file is first opened, i.e. only if/when it's needed.
22 * This API is used by SGI Performance Co-Pilot and other
23 * tools, see http://oss.sgi.com/projects/pcp
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/seq_file.h>
30 #include <linux/miscdevice.h>
31 #include <linux/utsname.h>
32 #include <linux/cpumask.h>
33 #include <linux/smp_lock.h>
34 #include <linux/nodemask.h>
35 #include <asm/processor.h>
36 #include <asm/topology.h>
38 #include <asm/semaphore.h>
39 #include <asm/uaccess.h>
41 #include <asm/sn/io.h>
42 #include <asm/sn/sn_sal.h>
43 #include <asm/sn/module.h>
44 #include <asm/sn/geo.h>
45 #include <asm/sn/sn2/sn_hwperf.h>
46 #include <asm/sn/addrs.h>
48 static void *sn_hwperf_salheap
= NULL
;
49 static int sn_hwperf_obj_cnt
= 0;
50 static nasid_t sn_hwperf_master_nasid
= INVALID_NASID
;
51 static int sn_hwperf_init(void);
52 static DECLARE_MUTEX(sn_hwperf_init_mutex
);
54 static int sn_hwperf_enum_objects(int *nobj
, struct sn_hwperf_object_info
**ret
)
58 struct sn_hwperf_object_info
*objbuf
= NULL
;
60 if ((e
= sn_hwperf_init()) < 0) {
61 printk(KERN_ERR
"sn_hwperf_init failed: err %d\n", e
);
65 sz
= sn_hwperf_obj_cnt
* sizeof(struct sn_hwperf_object_info
);
66 if ((objbuf
= (struct sn_hwperf_object_info
*) vmalloc(sz
)) == NULL
) {
67 printk("sn_hwperf_enum_objects: vmalloc(%d) failed\n", (int)sz
);
72 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, SN_HWPERF_ENUM_OBJECTS
,
73 0, sz
, (u64
) objbuf
, 0, 0, NULL
);
74 if (e
!= SN_HWPERF_OP_OK
) {
80 *nobj
= sn_hwperf_obj_cnt
;
85 static int sn_hwperf_location_to_bpos(char *location
,
86 int *rack
, int *bay
, int *slot
, int *slab
)
90 /* first scan for an old style geoid string */
91 if (sscanf(location
, "%03d%c%02d#%d",
92 rack
, &type
, bay
, slab
) == 4)
94 else /* scan for a new bladed geoid string */
95 if (sscanf(location
, "%03d%c%02d^%02d#%d",
96 rack
, &type
, bay
, slot
, slab
) != 5)
102 static int sn_hwperf_geoid_to_cnode(char *location
)
106 moduleid_t module_id
;
107 int rack
, bay
, slot
, slab
;
108 int this_rack
, this_bay
, this_slot
, this_slab
;
110 if (sn_hwperf_location_to_bpos(location
, &rack
, &bay
, &slot
, &slab
))
113 for_each_node(cnode
) {
114 geoid
= cnodeid_get_geoid(cnode
);
115 module_id
= geo_module(geoid
);
116 this_rack
= MODULE_GET_RACK(module_id
);
117 this_bay
= MODULE_GET_BPOS(module_id
);
118 this_slot
= geo_slot(geoid
);
119 this_slab
= geo_slab(geoid
);
120 if (rack
== this_rack
&& bay
== this_bay
&&
121 slot
== this_slot
&& slab
== this_slab
) {
126 return node_possible(cnode
) ? cnode
: -1;
129 static int sn_hwperf_obj_to_cnode(struct sn_hwperf_object_info
* obj
)
131 if (!SN_HWPERF_IS_NODE(obj
) && !SN_HWPERF_IS_IONODE(obj
))
133 if (!obj
->sn_hwp_this_part
)
135 return sn_hwperf_geoid_to_cnode(obj
->location
);
138 static int sn_hwperf_generic_ordinal(struct sn_hwperf_object_info
*obj
,
139 struct sn_hwperf_object_info
*objs
)
142 struct sn_hwperf_object_info
*p
;
144 for (ordinal
=0, p
=objs
; p
!= obj
; p
++) {
145 if (SN_HWPERF_FOREIGN(p
))
147 if (SN_HWPERF_SAME_OBJTYPE(p
, obj
))
154 static const char *slabname_node
= "node"; /* SHub asic */
155 static const char *slabname_ionode
= "ionode"; /* TIO asic */
156 static const char *slabname_router
= "router"; /* NL3R or NL4R */
157 static const char *slabname_other
= "other"; /* unknown asic */
159 static const char *sn_hwperf_get_slabname(struct sn_hwperf_object_info
*obj
,
160 struct sn_hwperf_object_info
*objs
, int *ordinal
)
163 const char *slabname
= slabname_other
;
165 if ((isnode
= SN_HWPERF_IS_NODE(obj
)) || SN_HWPERF_IS_IONODE(obj
)) {
166 slabname
= isnode
? slabname_node
: slabname_ionode
;
167 *ordinal
= sn_hwperf_obj_to_cnode(obj
);
170 *ordinal
= sn_hwperf_generic_ordinal(obj
, objs
);
171 if (SN_HWPERF_IS_ROUTER(obj
))
172 slabname
= slabname_router
;
178 static void print_pci_topology(struct seq_file
*s
)
184 for (sz
= PAGE_SIZE
; sz
< 16 * PAGE_SIZE
; sz
+= PAGE_SIZE
) {
185 if (!(p
= (char *)kmalloc(sz
, GFP_KERNEL
)))
187 e
= ia64_sn_ioif_get_pci_topology(__pa(p
), sz
);
191 if (e
== SALRET_OK
|| e
== SALRET_NOT_IMPLEMENTED
)
196 static inline int sn_hwperf_has_cpus(cnodeid_t node
)
198 return node_online(node
) && nr_cpus_node(node
);
201 static inline int sn_hwperf_has_mem(cnodeid_t node
)
203 return node_online(node
) && NODE_DATA(node
)->node_present_pages
;
206 static struct sn_hwperf_object_info
*
207 sn_hwperf_findobj_id(struct sn_hwperf_object_info
*objbuf
,
211 struct sn_hwperf_object_info
*p
= objbuf
;
213 for (i
=0; i
< nobj
; i
++, p
++) {
222 static int sn_hwperf_get_nearest_node_objdata(struct sn_hwperf_object_info
*objbuf
,
223 int nobj
, cnodeid_t node
, cnodeid_t
*near_mem_node
, cnodeid_t
*near_cpu_node
)
226 struct sn_hwperf_object_info
*nodeobj
= NULL
;
227 struct sn_hwperf_object_info
*op
;
228 struct sn_hwperf_object_info
*dest
;
229 struct sn_hwperf_object_info
*router
;
230 struct sn_hwperf_port_info ptdata
[16];
236 if (!node_possible(node
))
239 if (sn_hwperf_has_cpus(node
)) {
241 *near_cpu_node
= node
;
245 if (sn_hwperf_has_mem(node
)) {
247 *near_mem_node
= node
;
251 if (found_cpu
&& found_mem
)
252 return 0; /* trivially successful */
254 /* find the argument node object */
255 for (i
=0, op
=objbuf
; i
< nobj
; i
++, op
++) {
256 if (!SN_HWPERF_IS_NODE(op
) && !SN_HWPERF_IS_IONODE(op
))
258 if (node
== sn_hwperf_obj_to_cnode(op
)) {
268 /* get it's interconnect topology */
269 sz
= op
->ports
* sizeof(struct sn_hwperf_port_info
);
270 if (sz
> sizeof(ptdata
))
272 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
273 SN_HWPERF_ENUM_PORTS
, nodeobj
->id
, sz
,
274 (u64
)&ptdata
, 0, 0, NULL
);
275 if (e
!= SN_HWPERF_OP_OK
) {
280 /* find nearest node with cpus and nearest memory */
281 for (router
=NULL
, j
=0; j
< op
->ports
; j
++) {
282 dest
= sn_hwperf_findobj_id(objbuf
, nobj
, ptdata
[j
].conn_id
);
283 if (!dest
|| SN_HWPERF_FOREIGN(dest
) ||
284 !SN_HWPERF_IS_NODE(dest
) || SN_HWPERF_IS_IONODE(dest
)) {
287 c
= sn_hwperf_obj_to_cnode(dest
);
288 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
293 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
298 if (SN_HWPERF_IS_ROUTER(dest
))
302 if (router
&& (!found_cpu
|| !found_mem
)) {
303 /* search for a node connected to the same router */
304 sz
= router
->ports
* sizeof(struct sn_hwperf_port_info
);
305 if (sz
> sizeof(ptdata
))
307 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
308 SN_HWPERF_ENUM_PORTS
, router
->id
, sz
,
309 (u64
)&ptdata
, 0, 0, NULL
);
310 if (e
!= SN_HWPERF_OP_OK
) {
314 for (j
=0; j
< router
->ports
; j
++) {
315 dest
= sn_hwperf_findobj_id(objbuf
, nobj
,
317 if (!dest
|| dest
->id
== node
||
318 SN_HWPERF_FOREIGN(dest
) ||
319 !SN_HWPERF_IS_NODE(dest
) ||
320 SN_HWPERF_IS_IONODE(dest
)) {
323 c
= sn_hwperf_obj_to_cnode(dest
);
324 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
329 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
334 if (found_cpu
&& found_mem
)
339 if (!found_cpu
|| !found_mem
) {
340 /* resort to _any_ node with CPUs and memory */
341 for (i
=0, op
=objbuf
; i
< nobj
; i
++, op
++) {
342 if (SN_HWPERF_FOREIGN(op
) ||
343 SN_HWPERF_IS_IONODE(op
) ||
344 !SN_HWPERF_IS_NODE(op
)) {
347 c
= sn_hwperf_obj_to_cnode(op
);
348 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
353 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
358 if (found_cpu
&& found_mem
)
363 if (!found_cpu
|| !found_mem
)
371 static int sn_topology_show(struct seq_file
*s
, void *d
)
378 const char *slabname
;
382 struct cpuinfo_ia64
*c
;
383 struct sn_hwperf_port_info
*ptdata
;
384 struct sn_hwperf_object_info
*p
;
385 struct sn_hwperf_object_info
*obj
= d
; /* this object */
386 struct sn_hwperf_object_info
*objs
= s
->private; /* all objects */
398 seq_printf(s
, "# sn_topology version 2\n");
399 seq_printf(s
, "# objtype ordinal location partition"
400 " [attribute value [, ...]]\n");
402 if (ia64_sn_get_sn_info(0,
403 &shubtype
, &nasid_mask
, &nasid_shift
, &system_size
,
404 &sharing_size
, &partid
, &coher
, ®ion_size
))
406 for (nasid_msb
=63; nasid_msb
> 0; nasid_msb
--) {
407 if (((u64
)nasid_mask
<< nasid_shift
) & (1ULL << nasid_msb
))
410 seq_printf(s
, "partition %u %s local "
412 "nasid_mask 0x%016lx, "
416 "coherency_domain %d, "
419 partid
, system_utsname
.nodename
,
420 shubtype
? "shub2" : "shub1",
421 (u64
)nasid_mask
<< nasid_shift
, nasid_msb
, nasid_shift
,
422 system_size
, sharing_size
, coher
, region_size
);
424 print_pci_topology(s
);
427 if (SN_HWPERF_FOREIGN(obj
)) {
428 /* private in another partition: not interesting */
432 for (i
= 0; i
< SN_HWPERF_MAXSTRING
&& obj
->name
[i
]; i
++) {
433 if (obj
->name
[i
] == ' ')
437 slabname
= sn_hwperf_get_slabname(obj
, objs
, &ordinal
);
438 seq_printf(s
, "%s %d %s %s asic %s", slabname
, ordinal
, obj
->location
,
439 obj
->sn_hwp_this_part
? "local" : "shared", obj
->name
);
441 if (!SN_HWPERF_IS_NODE(obj
) && !SN_HWPERF_IS_IONODE(obj
))
444 cnodeid_t near_mem
= -1;
445 cnodeid_t near_cpu
= -1;
447 seq_printf(s
, ", nasid 0x%x", cnodeid_to_nasid(ordinal
));
449 if (sn_hwperf_get_nearest_node_objdata(objs
, sn_hwperf_obj_cnt
,
450 ordinal
, &near_mem
, &near_cpu
) == 0) {
451 seq_printf(s
, ", near_mem_nodeid %d, near_cpu_nodeid %d",
455 if (!SN_HWPERF_IS_IONODE(obj
)) {
456 for_each_online_node(i
) {
457 seq_printf(s
, i
? ":%d" : ", dist %d",
458 node_distance(ordinal
, i
));
465 * CPUs on this node, if any
467 cpumask
= node_to_cpumask(ordinal
);
468 for_each_online_cpu(i
) {
469 if (cpu_isset(i
, cpumask
)) {
470 slice
= 'a' + cpuid_to_slice(i
);
472 seq_printf(s
, "cpu %d %s%c local"
473 " freq %luMHz, arch ia64",
474 i
, obj
->location
, slice
,
475 c
->proc_freq
/ 1000000);
476 for_each_online_cpu(j
) {
477 seq_printf(s
, j
? ":%d" : ", dist %d",
491 sz
= obj
->ports
* sizeof(struct sn_hwperf_port_info
);
492 if ((ptdata
= vmalloc(sz
)) == NULL
)
494 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
495 SN_HWPERF_ENUM_PORTS
, obj
->id
, sz
,
496 (u64
) ptdata
, 0, 0, NULL
);
497 if (e
!= SN_HWPERF_OP_OK
)
499 for (ordinal
=0, p
=objs
; p
!= obj
; p
++) {
500 if (!SN_HWPERF_FOREIGN(p
))
503 for (pt
= 0; pt
< obj
->ports
; pt
++) {
504 for (p
= objs
, i
= 0; i
< sn_hwperf_obj_cnt
; i
++, p
++) {
505 if (ptdata
[pt
].conn_id
== p
->id
) {
509 seq_printf(s
, "numalink %d %s-%d",
510 ordinal
+pt
, obj
->location
, ptdata
[pt
].port
);
512 if (i
>= sn_hwperf_obj_cnt
) {
514 seq_puts(s
, " local endpoint disconnected"
515 ", protocol unknown\n");
519 if (obj
->sn_hwp_this_part
&& p
->sn_hwp_this_part
)
520 /* both ends local to this partition */
521 seq_puts(s
, " local");
522 else if (!obj
->sn_hwp_this_part
&& !p
->sn_hwp_this_part
)
523 /* both ends of the link in foreign partiton */
524 seq_puts(s
, " foreign");
526 /* link straddles a partition */
527 seq_puts(s
, " shared");
530 * Unlikely, but strictly should query the LLP config
531 * registers because an NL4R can be configured to run
532 * NL3 protocol, even when not talking to an NL3 router.
533 * Ditto for node-node.
535 seq_printf(s
, " endpoint %s-%d, protocol %s\n",
536 p
->location
, ptdata
[pt
].conn_port
,
537 (SN_HWPERF_IS_NL3ROUTER(obj
) ||
538 SN_HWPERF_IS_NL3ROUTER(p
)) ? "LLP3" : "LLP4");
546 static void *sn_topology_start(struct seq_file
*s
, loff_t
* pos
)
548 struct sn_hwperf_object_info
*objs
= s
->private;
550 if (*pos
< sn_hwperf_obj_cnt
)
551 return (void *)(objs
+ *pos
);
556 static void *sn_topology_next(struct seq_file
*s
, void *v
, loff_t
* pos
)
559 return sn_topology_start(s
, pos
);
562 static void sn_topology_stop(struct seq_file
*m
, void *v
)
568 * /proc/sgi_sn/sn_topology, read-only using seq_file
570 static struct seq_operations sn_topology_seq_ops
= {
571 .start
= sn_topology_start
,
572 .next
= sn_topology_next
,
573 .stop
= sn_topology_stop
,
574 .show
= sn_topology_show
577 struct sn_hwperf_op_info
{
579 struct sn_hwperf_ioctl_args
*a
;
585 static void sn_hwperf_call_sal(void *info
)
587 struct sn_hwperf_op_info
*op_info
= info
;
590 r
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, op_info
->op
,
591 op_info
->a
->arg
, op_info
->a
->sz
,
592 (u64
) op_info
->p
, 0, 0, op_info
->v0
);
596 static int sn_hwperf_op_cpu(struct sn_hwperf_op_info
*op_info
)
601 cpumask_t save_allowed
;
603 cpu
= (op_info
->a
->arg
& SN_HWPERF_ARG_CPU_MASK
) >> 32;
604 use_ipi
= op_info
->a
->arg
& SN_HWPERF_ARG_USE_IPI_MASK
;
605 op_info
->a
->arg
&= SN_HWPERF_ARG_OBJID_MASK
;
607 if (cpu
!= SN_HWPERF_ARG_ANY_CPU
) {
608 if (cpu
>= num_online_cpus() || !cpu_online(cpu
)) {
614 if (cpu
== SN_HWPERF_ARG_ANY_CPU
|| cpu
== get_cpu()) {
615 /* don't care, or already on correct cpu */
616 sn_hwperf_call_sal(op_info
);
620 /* use an interprocessor interrupt to call SAL */
621 smp_call_function_single(cpu
, sn_hwperf_call_sal
,
625 /* migrate the task before calling SAL */
626 save_allowed
= current
->cpus_allowed
;
627 set_cpus_allowed(current
, cpumask_of_cpu(cpu
));
628 sn_hwperf_call_sal(op_info
);
629 set_cpus_allowed(current
, save_allowed
);
638 /* map SAL hwperf error code to system error code */
639 static int sn_hwperf_map_err(int hwperf_err
)
644 case SN_HWPERF_OP_OK
:
648 case SN_HWPERF_OP_NOMEM
:
652 case SN_HWPERF_OP_NO_PERM
:
656 case SN_HWPERF_OP_IO_ERROR
:
660 case SN_HWPERF_OP_BUSY
:
664 case SN_HWPERF_OP_RECONFIGURE
:
668 case SN_HWPERF_OP_INVAL
:
678 * ioctl for "sn_hwperf" misc device
681 sn_hwperf_ioctl(struct inode
*in
, struct file
*fp
, u32 op
, u64 arg
)
683 struct sn_hwperf_ioctl_args a
;
684 struct cpuinfo_ia64
*cdata
;
685 struct sn_hwperf_object_info
*objs
;
686 struct sn_hwperf_object_info
*cpuobj
;
687 struct sn_hwperf_op_info op_info
;
699 /* only user requests are allowed here */
700 if ((op
& SN_HWPERF_OP_MASK
) < 10) {
704 r
= copy_from_user(&a
, (const void __user
*)arg
,
705 sizeof(struct sn_hwperf_ioctl_args
));
712 * Allocate memory to hold a kernel copy of the user buffer. The
713 * buffer contents are either copied in or out (or both) of user
714 * space depending on the flags encoded in the requested operation.
724 if (op
& SN_HWPERF_OP_MEM_COPYIN
) {
725 r
= copy_from_user(p
, (const void __user
*)a
.ptr
, a
.sz
);
733 case SN_HWPERF_GET_CPU_INFO
:
734 if (a
.sz
== sizeof(u64
)) {
735 /* special case to get size needed */
736 *(u64
*) p
= (u64
) num_online_cpus() *
737 sizeof(struct sn_hwperf_object_info
);
739 if (a
.sz
< num_online_cpus() * sizeof(struct sn_hwperf_object_info
)) {
743 if ((r
= sn_hwperf_enum_objects(&nobj
, &objs
)) == 0) {
745 for (i
= 0; i
< nobj
; i
++) {
746 if (!SN_HWPERF_IS_NODE(objs
+ i
))
748 node
= sn_hwperf_obj_to_cnode(objs
+ i
);
749 for_each_online_cpu(j
) {
750 if (node
!= cpu_to_node(j
))
752 cpuobj
= (struct sn_hwperf_object_info
*) p
+ j
;
753 slice
= 'a' + cpuid_to_slice(j
);
756 snprintf(cpuobj
->name
,
757 sizeof(cpuobj
->name
),
759 cdata
->proc_freq
/ 1000000,
761 snprintf(cpuobj
->location
,
762 sizeof(cpuobj
->location
),
763 "%s%c", objs
[i
].location
,
772 case SN_HWPERF_GET_NODE_NASID
:
773 if (a
.sz
!= sizeof(u64
) ||
774 (node
= a
.arg
) < 0 || !node_possible(node
)) {
778 *(u64
*)p
= (u64
)cnodeid_to_nasid(node
);
781 case SN_HWPERF_GET_OBJ_NODE
:
782 if (a
.sz
!= sizeof(u64
) || a
.arg
< 0) {
786 if ((r
= sn_hwperf_enum_objects(&nobj
, &objs
)) == 0) {
792 if (objs
[(i
= a
.arg
)].id
!= a
.arg
) {
793 for (i
= 0; i
< nobj
; i
++) {
794 if (objs
[i
].id
== a
.arg
)
804 if (!SN_HWPERF_IS_NODE(objs
+ i
) &&
805 !SN_HWPERF_IS_IONODE(objs
+ i
)) {
811 *(u64
*)p
= (u64
)sn_hwperf_obj_to_cnode(objs
+ i
);
816 case SN_HWPERF_GET_MMRS
:
817 case SN_HWPERF_SET_MMRS
:
818 case SN_HWPERF_OBJECT_DISTANCE
:
823 r
= sn_hwperf_op_cpu(&op_info
);
825 r
= sn_hwperf_map_err(r
);
832 /* all other ops are a direct SAL call */
833 r
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, op
,
834 a
.arg
, a
.sz
, (u64
) p
, 0, 0, &v0
);
836 r
= sn_hwperf_map_err(r
);
843 if (op
& SN_HWPERF_OP_MEM_COPYOUT
) {
844 r
= copy_to_user((void __user
*)a
.ptr
, p
, a
.sz
);
858 static struct file_operations sn_hwperf_fops
= {
859 .ioctl
= sn_hwperf_ioctl
,
862 static struct miscdevice sn_hwperf_dev
= {
868 static int sn_hwperf_init(void)
874 /* single threaded, once-only initialization */
875 down(&sn_hwperf_init_mutex
);
877 if (sn_hwperf_salheap
) {
878 up(&sn_hwperf_init_mutex
);
883 * The PROM code needs a fixed reference node. For convenience the
884 * same node as the console I/O is used.
886 sn_hwperf_master_nasid
= (nasid_t
) ia64_sn_get_console_nasid();
889 * Request the needed size and install the PROM scratch area.
890 * The PROM keeps various tracking bits in this memory area.
892 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
893 (u64
) SN_HWPERF_GET_HEAPSIZE
, 0,
894 (u64
) sizeof(u64
), (u64
) &v
, 0, 0, NULL
);
895 if (salr
!= SN_HWPERF_OP_OK
) {
900 if ((sn_hwperf_salheap
= vmalloc(v
)) == NULL
) {
904 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
905 SN_HWPERF_INSTALL_HEAP
, 0, v
,
906 (u64
) sn_hwperf_salheap
, 0, 0, NULL
);
907 if (salr
!= SN_HWPERF_OP_OK
) {
912 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
913 SN_HWPERF_OBJECT_COUNT
, 0,
914 sizeof(u64
), (u64
) &v
, 0, 0, NULL
);
915 if (salr
!= SN_HWPERF_OP_OK
) {
919 sn_hwperf_obj_cnt
= (int)v
;
922 if (e
< 0 && sn_hwperf_salheap
) {
923 vfree(sn_hwperf_salheap
);
924 sn_hwperf_salheap
= NULL
;
925 sn_hwperf_obj_cnt
= 0;
927 up(&sn_hwperf_init_mutex
);
931 int sn_topology_open(struct inode
*inode
, struct file
*file
)
934 struct seq_file
*seq
;
935 struct sn_hwperf_object_info
*objbuf
;
938 if ((e
= sn_hwperf_enum_objects(&nobj
, &objbuf
)) == 0) {
939 e
= seq_open(file
, &sn_topology_seq_ops
);
940 seq
= file
->private_data
;
941 seq
->private = objbuf
;
947 int sn_topology_release(struct inode
*inode
, struct file
*file
)
949 struct seq_file
*seq
= file
->private_data
;
952 return seq_release(inode
, file
);
955 int sn_hwperf_get_nearest_node(cnodeid_t node
,
956 cnodeid_t
*near_mem_node
, cnodeid_t
*near_cpu_node
)
960 struct sn_hwperf_object_info
*objbuf
;
962 if ((e
= sn_hwperf_enum_objects(&nobj
, &objbuf
)) == 0) {
963 e
= sn_hwperf_get_nearest_node_objdata(objbuf
, nobj
,
964 node
, near_mem_node
, near_cpu_node
);
971 static int __devinit
sn_hwperf_misc_register_init(void)
978 * Register a dynamic misc device for hwperf ioctls. Platforms
979 * supporting hotplug will create /dev/sn_hwperf, else user
980 * can to look up the minor number in /proc/misc.
982 if ((e
= misc_register(&sn_hwperf_dev
)) != 0) {
983 printk(KERN_ERR
"sn_hwperf_misc_register_init: failed to "
984 "register misc device for \"%s\"\n", sn_hwperf_dev
.name
);
990 device_initcall(sn_hwperf_misc_register_init
); /* after misc_init() */
991 EXPORT_SYMBOL(sn_hwperf_get_nearest_node
);