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-2006 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/nodemask.h>
34 #include <linux/smp.h>
35 #include <linux/mutex.h>
37 #include <asm/processor.h>
38 #include <asm/topology.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 DEFINE_MUTEX(sn_hwperf_init_mutex
);
54 #define cnode_possible(n) ((n) < num_cnodes)
56 static int sn_hwperf_enum_objects(int *nobj
, struct sn_hwperf_object_info
**ret
)
60 struct sn_hwperf_object_info
*objbuf
= NULL
;
62 if ((e
= sn_hwperf_init()) < 0) {
63 printk(KERN_ERR
"sn_hwperf_init failed: err %d\n", e
);
67 sz
= sn_hwperf_obj_cnt
* sizeof(struct sn_hwperf_object_info
);
70 printk("sn_hwperf_enum_objects: vmalloc(%d) failed\n", (int)sz
);
75 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, SN_HWPERF_ENUM_OBJECTS
,
76 0, sz
, (u64
) objbuf
, 0, 0, NULL
);
77 if (e
!= SN_HWPERF_OP_OK
) {
83 *nobj
= sn_hwperf_obj_cnt
;
88 static int sn_hwperf_location_to_bpos(char *location
,
89 int *rack
, int *bay
, int *slot
, int *slab
)
93 /* first scan for an old style geoid string */
94 if (sscanf(location
, "%03d%c%02d#%d",
95 rack
, &type
, bay
, slab
) == 4)
97 else /* scan for a new bladed geoid string */
98 if (sscanf(location
, "%03d%c%02d^%02d#%d",
99 rack
, &type
, bay
, slot
, slab
) != 5)
105 static int sn_hwperf_geoid_to_cnode(char *location
)
109 moduleid_t module_id
;
110 int rack
, bay
, slot
, slab
;
111 int this_rack
, this_bay
, this_slot
, this_slab
;
113 if (sn_hwperf_location_to_bpos(location
, &rack
, &bay
, &slot
, &slab
))
117 * FIXME: replace with cleaner for_each_XXX macro which addresses
118 * both compute and IO nodes once ACPI3.0 is available.
120 for (cnode
= 0; cnode
< num_cnodes
; cnode
++) {
121 geoid
= cnodeid_get_geoid(cnode
);
122 module_id
= geo_module(geoid
);
123 this_rack
= MODULE_GET_RACK(module_id
);
124 this_bay
= MODULE_GET_BPOS(module_id
);
125 this_slot
= geo_slot(geoid
);
126 this_slab
= geo_slab(geoid
);
127 if (rack
== this_rack
&& bay
== this_bay
&&
128 slot
== this_slot
&& slab
== this_slab
) {
133 return cnode_possible(cnode
) ? cnode
: -1;
136 static int sn_hwperf_obj_to_cnode(struct sn_hwperf_object_info
* obj
)
138 if (!SN_HWPERF_IS_NODE(obj
) && !SN_HWPERF_IS_IONODE(obj
))
140 if (SN_HWPERF_FOREIGN(obj
))
142 return sn_hwperf_geoid_to_cnode(obj
->location
);
145 static int sn_hwperf_generic_ordinal(struct sn_hwperf_object_info
*obj
,
146 struct sn_hwperf_object_info
*objs
)
149 struct sn_hwperf_object_info
*p
;
151 for (ordinal
=0, p
=objs
; p
!= obj
; p
++) {
152 if (SN_HWPERF_FOREIGN(p
))
154 if (SN_HWPERF_SAME_OBJTYPE(p
, obj
))
161 static const char *slabname_node
= "node"; /* SHub asic */
162 static const char *slabname_ionode
= "ionode"; /* TIO asic */
163 static const char *slabname_router
= "router"; /* NL3R or NL4R */
164 static const char *slabname_other
= "other"; /* unknown asic */
166 static const char *sn_hwperf_get_slabname(struct sn_hwperf_object_info
*obj
,
167 struct sn_hwperf_object_info
*objs
, int *ordinal
)
170 const char *slabname
= slabname_other
;
172 if ((isnode
= SN_HWPERF_IS_NODE(obj
)) || SN_HWPERF_IS_IONODE(obj
)) {
173 slabname
= isnode
? slabname_node
: slabname_ionode
;
174 *ordinal
= sn_hwperf_obj_to_cnode(obj
);
177 *ordinal
= sn_hwperf_generic_ordinal(obj
, objs
);
178 if (SN_HWPERF_IS_ROUTER(obj
))
179 slabname
= slabname_router
;
185 static void print_pci_topology(struct seq_file
*s
)
191 for (sz
= PAGE_SIZE
; sz
< 16 * PAGE_SIZE
; sz
+= PAGE_SIZE
) {
192 if (!(p
= kmalloc(sz
, GFP_KERNEL
)))
194 e
= ia64_sn_ioif_get_pci_topology(__pa(p
), sz
);
198 if (e
== SALRET_OK
|| e
== SALRET_NOT_IMPLEMENTED
)
203 static inline int sn_hwperf_has_cpus(cnodeid_t node
)
205 return node
< MAX_NUMNODES
&& node_online(node
) && nr_cpus_node(node
);
208 static inline int sn_hwperf_has_mem(cnodeid_t node
)
210 return node
< MAX_NUMNODES
&& node_online(node
) && NODE_DATA(node
)->node_present_pages
;
213 static struct sn_hwperf_object_info
*
214 sn_hwperf_findobj_id(struct sn_hwperf_object_info
*objbuf
,
218 struct sn_hwperf_object_info
*p
= objbuf
;
220 for (i
=0; i
< nobj
; i
++, p
++) {
229 static int sn_hwperf_get_nearest_node_objdata(struct sn_hwperf_object_info
*objbuf
,
230 int nobj
, cnodeid_t node
, cnodeid_t
*near_mem_node
, cnodeid_t
*near_cpu_node
)
233 struct sn_hwperf_object_info
*nodeobj
= NULL
;
234 struct sn_hwperf_object_info
*op
;
235 struct sn_hwperf_object_info
*dest
;
236 struct sn_hwperf_object_info
*router
;
237 struct sn_hwperf_port_info ptdata
[16];
243 if (!cnode_possible(node
))
246 if (sn_hwperf_has_cpus(node
)) {
248 *near_cpu_node
= node
;
252 if (sn_hwperf_has_mem(node
)) {
254 *near_mem_node
= node
;
258 if (found_cpu
&& found_mem
)
259 return 0; /* trivially successful */
261 /* find the argument node object */
262 for (i
=0, op
=objbuf
; i
< nobj
; i
++, op
++) {
263 if (!SN_HWPERF_IS_NODE(op
) && !SN_HWPERF_IS_IONODE(op
))
265 if (node
== sn_hwperf_obj_to_cnode(op
)) {
275 /* get it's interconnect topology */
276 sz
= op
->ports
* sizeof(struct sn_hwperf_port_info
);
277 BUG_ON(sz
> sizeof(ptdata
));
278 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
279 SN_HWPERF_ENUM_PORTS
, nodeobj
->id
, sz
,
280 (u64
)&ptdata
, 0, 0, NULL
);
281 if (e
!= SN_HWPERF_OP_OK
) {
286 /* find nearest node with cpus and nearest memory */
287 for (router
=NULL
, j
=0; j
< op
->ports
; j
++) {
288 dest
= sn_hwperf_findobj_id(objbuf
, nobj
, ptdata
[j
].conn_id
);
289 if (dest
&& SN_HWPERF_IS_ROUTER(dest
))
291 if (!dest
|| SN_HWPERF_FOREIGN(dest
) ||
292 !SN_HWPERF_IS_NODE(dest
) || SN_HWPERF_IS_IONODE(dest
)) {
295 c
= sn_hwperf_obj_to_cnode(dest
);
296 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
301 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
308 if (router
&& (!found_cpu
|| !found_mem
)) {
309 /* search for a node connected to the same router */
310 sz
= router
->ports
* sizeof(struct sn_hwperf_port_info
);
311 BUG_ON(sz
> sizeof(ptdata
));
312 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
313 SN_HWPERF_ENUM_PORTS
, router
->id
, sz
,
314 (u64
)&ptdata
, 0, 0, NULL
);
315 if (e
!= SN_HWPERF_OP_OK
) {
319 for (j
=0; j
< router
->ports
; j
++) {
320 dest
= sn_hwperf_findobj_id(objbuf
, nobj
,
322 if (!dest
|| dest
->id
== node
||
323 SN_HWPERF_FOREIGN(dest
) ||
324 !SN_HWPERF_IS_NODE(dest
) ||
325 SN_HWPERF_IS_IONODE(dest
)) {
328 c
= sn_hwperf_obj_to_cnode(dest
);
329 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
334 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
339 if (found_cpu
&& found_mem
)
344 if (!found_cpu
|| !found_mem
) {
345 /* resort to _any_ node with CPUs and memory */
346 for (i
=0, op
=objbuf
; i
< nobj
; i
++, op
++) {
347 if (SN_HWPERF_FOREIGN(op
) ||
348 SN_HWPERF_IS_IONODE(op
) ||
349 !SN_HWPERF_IS_NODE(op
)) {
352 c
= sn_hwperf_obj_to_cnode(op
);
353 if (!found_cpu
&& sn_hwperf_has_cpus(c
)) {
358 if (!found_mem
&& sn_hwperf_has_mem(c
)) {
363 if (found_cpu
&& found_mem
)
368 if (!found_cpu
|| !found_mem
)
376 static int sn_topology_show(struct seq_file
*s
, void *d
)
383 const char *slabname
;
386 struct cpuinfo_ia64
*c
;
387 struct sn_hwperf_port_info
*ptdata
;
388 struct sn_hwperf_object_info
*p
;
389 struct sn_hwperf_object_info
*obj
= d
; /* this object */
390 struct sn_hwperf_object_info
*objs
= s
->private; /* all objects */
402 seq_printf(s
, "# sn_topology version 2\n");
403 seq_printf(s
, "# objtype ordinal location partition"
404 " [attribute value [, ...]]\n");
406 if (ia64_sn_get_sn_info(0,
407 &shubtype
, &nasid_mask
, &nasid_shift
, &system_size
,
408 &sharing_size
, &partid
, &coher
, ®ion_size
))
410 for (nasid_msb
=63; nasid_msb
> 0; nasid_msb
--) {
411 if (((u64
)nasid_mask
<< nasid_shift
) & (1ULL << nasid_msb
))
414 seq_printf(s
, "partition %u %s local "
416 "nasid_mask 0x%016llx, "
420 "coherency_domain %d, "
423 partid
, utsname()->nodename
,
424 shubtype
? "shub2" : "shub1",
425 (u64
)nasid_mask
<< nasid_shift
, nasid_msb
, nasid_shift
,
426 system_size
, sharing_size
, coher
, region_size
);
428 print_pci_topology(s
);
431 if (SN_HWPERF_FOREIGN(obj
)) {
432 /* private in another partition: not interesting */
436 for (i
= 0; i
< SN_HWPERF_MAXSTRING
&& obj
->name
[i
]; i
++) {
437 if (obj
->name
[i
] == ' ')
441 slabname
= sn_hwperf_get_slabname(obj
, objs
, &ordinal
);
442 seq_printf(s
, "%s %d %s %s asic %s", slabname
, ordinal
, obj
->location
,
443 obj
->sn_hwp_this_part
? "local" : "shared", obj
->name
);
445 if (ordinal
< 0 || (!SN_HWPERF_IS_NODE(obj
) && !SN_HWPERF_IS_IONODE(obj
)))
448 cnodeid_t near_mem
= -1;
449 cnodeid_t near_cpu
= -1;
451 seq_printf(s
, ", nasid 0x%x", cnodeid_to_nasid(ordinal
));
453 if (sn_hwperf_get_nearest_node_objdata(objs
, sn_hwperf_obj_cnt
,
454 ordinal
, &near_mem
, &near_cpu
) == 0) {
455 seq_printf(s
, ", near_mem_nodeid %d, near_cpu_nodeid %d",
459 if (!SN_HWPERF_IS_IONODE(obj
)) {
460 for_each_online_node(i
) {
461 seq_printf(s
, i
? ":%d" : ", dist %d",
462 node_distance(ordinal
, i
));
469 * CPUs on this node, if any
471 if (!SN_HWPERF_IS_IONODE(obj
)) {
472 for_each_cpu_and(i
, cpu_online_mask
,
473 cpumask_of_node(ordinal
)) {
474 slice
= 'a' + cpuid_to_slice(i
);
476 seq_printf(s
, "cpu %d %s%c local"
477 " freq %luMHz, arch ia64",
478 i
, obj
->location
, slice
,
479 c
->proc_freq
/ 1000000);
480 for_each_online_cpu(j
) {
481 seq_printf(s
, j
? ":%d" : ", dist %d",
495 sz
= obj
->ports
* sizeof(struct sn_hwperf_port_info
);
496 if ((ptdata
= kmalloc(sz
, GFP_KERNEL
)) == NULL
)
498 e
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
499 SN_HWPERF_ENUM_PORTS
, obj
->id
, sz
,
500 (u64
) ptdata
, 0, 0, NULL
);
501 if (e
!= SN_HWPERF_OP_OK
)
503 for (ordinal
=0, p
=objs
; p
!= obj
; p
++) {
504 if (!SN_HWPERF_FOREIGN(p
))
507 for (pt
= 0; pt
< obj
->ports
; pt
++) {
508 for (p
= objs
, i
= 0; i
< sn_hwperf_obj_cnt
; i
++, p
++) {
509 if (ptdata
[pt
].conn_id
== p
->id
) {
513 seq_printf(s
, "numalink %d %s-%d",
514 ordinal
+pt
, obj
->location
, ptdata
[pt
].port
);
516 if (i
>= sn_hwperf_obj_cnt
) {
518 seq_puts(s
, " local endpoint disconnected"
519 ", protocol unknown\n");
523 if (obj
->sn_hwp_this_part
&& p
->sn_hwp_this_part
)
524 /* both ends local to this partition */
525 seq_puts(s
, " local");
526 else if (SN_HWPERF_FOREIGN(p
))
527 /* both ends of the link in foreign partiton */
528 seq_puts(s
, " foreign");
530 /* link straddles a partition */
531 seq_puts(s
, " shared");
534 * Unlikely, but strictly should query the LLP config
535 * registers because an NL4R can be configured to run
536 * NL3 protocol, even when not talking to an NL3 router.
537 * Ditto for node-node.
539 seq_printf(s
, " endpoint %s-%d, protocol %s\n",
540 p
->location
, ptdata
[pt
].conn_port
,
541 (SN_HWPERF_IS_NL3ROUTER(obj
) ||
542 SN_HWPERF_IS_NL3ROUTER(p
)) ? "LLP3" : "LLP4");
550 static void *sn_topology_start(struct seq_file
*s
, loff_t
* pos
)
552 struct sn_hwperf_object_info
*objs
= s
->private;
554 if (*pos
< sn_hwperf_obj_cnt
)
555 return (void *)(objs
+ *pos
);
560 static void *sn_topology_next(struct seq_file
*s
, void *v
, loff_t
* pos
)
563 return sn_topology_start(s
, pos
);
566 static void sn_topology_stop(struct seq_file
*m
, void *v
)
572 * /proc/sgi_sn/sn_topology, read-only using seq_file
574 static const struct seq_operations sn_topology_seq_ops
= {
575 .start
= sn_topology_start
,
576 .next
= sn_topology_next
,
577 .stop
= sn_topology_stop
,
578 .show
= sn_topology_show
581 struct sn_hwperf_op_info
{
583 struct sn_hwperf_ioctl_args
*a
;
589 static void sn_hwperf_call_sal(void *info
)
591 struct sn_hwperf_op_info
*op_info
= info
;
594 r
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, op_info
->op
,
595 op_info
->a
->arg
, op_info
->a
->sz
,
596 (u64
) op_info
->p
, 0, 0, op_info
->v0
);
600 static int sn_hwperf_op_cpu(struct sn_hwperf_op_info
*op_info
)
605 cpumask_t save_allowed
;
607 cpu
= (op_info
->a
->arg
& SN_HWPERF_ARG_CPU_MASK
) >> 32;
608 use_ipi
= op_info
->a
->arg
& SN_HWPERF_ARG_USE_IPI_MASK
;
609 op_info
->a
->arg
&= SN_HWPERF_ARG_OBJID_MASK
;
611 if (cpu
!= SN_HWPERF_ARG_ANY_CPU
) {
612 if (cpu
>= nr_cpu_ids
|| !cpu_online(cpu
)) {
618 if (cpu
== SN_HWPERF_ARG_ANY_CPU
) {
619 /* don't care which cpu */
620 sn_hwperf_call_sal(op_info
);
621 } else if (cpu
== get_cpu()) {
622 /* already on correct cpu */
623 sn_hwperf_call_sal(op_info
);
628 /* use an interprocessor interrupt to call SAL */
629 smp_call_function_single(cpu
, sn_hwperf_call_sal
,
633 /* migrate the task before calling SAL */
634 save_allowed
= current
->cpus_allowed
;
635 set_cpus_allowed_ptr(current
, cpumask_of(cpu
));
636 sn_hwperf_call_sal(op_info
);
637 set_cpus_allowed_ptr(current
, &save_allowed
);
646 /* map SAL hwperf error code to system error code */
647 static int sn_hwperf_map_err(int hwperf_err
)
652 case SN_HWPERF_OP_OK
:
656 case SN_HWPERF_OP_NOMEM
:
660 case SN_HWPERF_OP_NO_PERM
:
664 case SN_HWPERF_OP_IO_ERROR
:
668 case SN_HWPERF_OP_BUSY
:
672 case SN_HWPERF_OP_RECONFIGURE
:
676 case SN_HWPERF_OP_INVAL
:
686 * ioctl for "sn_hwperf" misc device
688 static long sn_hwperf_ioctl(struct file
*fp
, u32 op
, unsigned long arg
)
690 struct sn_hwperf_ioctl_args a
;
691 struct cpuinfo_ia64
*cdata
;
692 struct sn_hwperf_object_info
*objs
;
693 struct sn_hwperf_object_info
*cpuobj
;
694 struct sn_hwperf_op_info op_info
;
704 /* only user requests are allowed here */
705 if ((op
& SN_HWPERF_OP_MASK
) < 10) {
709 r
= copy_from_user(&a
, (const void __user
*)arg
,
710 sizeof(struct sn_hwperf_ioctl_args
));
717 * Allocate memory to hold a kernel copy of the user buffer. The
718 * buffer contents are either copied in or out (or both) of user
719 * space depending on the flags encoded in the requested operation.
729 if (op
& SN_HWPERF_OP_MEM_COPYIN
) {
730 r
= copy_from_user(p
, (const void __user
*)a
.ptr
, a
.sz
);
738 case SN_HWPERF_GET_CPU_INFO
:
739 if (a
.sz
== sizeof(u64
)) {
740 /* special case to get size needed */
741 *(u64
*) p
= (u64
) num_online_cpus() *
742 sizeof(struct sn_hwperf_object_info
);
744 if (a
.sz
< num_online_cpus() * sizeof(struct sn_hwperf_object_info
)) {
748 if ((r
= sn_hwperf_enum_objects(&nobj
, &objs
)) == 0) {
749 int cpuobj_index
= 0;
752 for (i
= 0; i
< nobj
; i
++) {
753 if (!SN_HWPERF_IS_NODE(objs
+ i
))
755 node
= sn_hwperf_obj_to_cnode(objs
+ i
);
756 for_each_online_cpu(j
) {
757 if (node
!= cpu_to_node(j
))
759 cpuobj
= (struct sn_hwperf_object_info
*) p
+ cpuobj_index
++;
760 slice
= 'a' + cpuid_to_slice(j
);
763 snprintf(cpuobj
->name
,
764 sizeof(cpuobj
->name
),
766 cdata
->proc_freq
/ 1000000,
768 snprintf(cpuobj
->location
,
769 sizeof(cpuobj
->location
),
770 "%s%c", objs
[i
].location
,
779 case SN_HWPERF_GET_NODE_NASID
:
780 if (a
.sz
!= sizeof(u64
) ||
781 (node
= a
.arg
) < 0 || !cnode_possible(node
)) {
785 *(u64
*)p
= (u64
)cnodeid_to_nasid(node
);
788 case SN_HWPERF_GET_OBJ_NODE
:
790 if (a
.sz
!= sizeof(u64
) || i
< 0) {
794 if ((r
= sn_hwperf_enum_objects(&nobj
, &objs
)) == 0) {
800 if (objs
[i
].id
!= a
.arg
) {
801 for (i
= 0; i
< nobj
; i
++) {
802 if (objs
[i
].id
== a
.arg
)
812 if (!SN_HWPERF_IS_NODE(objs
+ i
) &&
813 !SN_HWPERF_IS_IONODE(objs
+ i
)) {
819 *(u64
*)p
= (u64
)sn_hwperf_obj_to_cnode(objs
+ i
);
824 case SN_HWPERF_GET_MMRS
:
825 case SN_HWPERF_SET_MMRS
:
826 case SN_HWPERF_OBJECT_DISTANCE
:
831 r
= sn_hwperf_op_cpu(&op_info
);
833 r
= sn_hwperf_map_err(r
);
840 /* all other ops are a direct SAL call */
841 r
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
, op
,
842 a
.arg
, a
.sz
, (u64
) p
, 0, 0, &v0
);
844 r
= sn_hwperf_map_err(r
);
851 if (op
& SN_HWPERF_OP_MEM_COPYOUT
) {
852 r
= copy_to_user((void __user
*)a
.ptr
, p
, a
.sz
);
865 static const struct file_operations sn_hwperf_fops
= {
866 .unlocked_ioctl
= sn_hwperf_ioctl
,
867 .llseek
= noop_llseek
,
870 static struct miscdevice sn_hwperf_dev
= {
876 static int sn_hwperf_init(void)
882 /* single threaded, once-only initialization */
883 mutex_lock(&sn_hwperf_init_mutex
);
885 if (sn_hwperf_salheap
) {
886 mutex_unlock(&sn_hwperf_init_mutex
);
891 * The PROM code needs a fixed reference node. For convenience the
892 * same node as the console I/O is used.
894 sn_hwperf_master_nasid
= (nasid_t
) ia64_sn_get_console_nasid();
897 * Request the needed size and install the PROM scratch area.
898 * The PROM keeps various tracking bits in this memory area.
900 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
901 (u64
) SN_HWPERF_GET_HEAPSIZE
, 0,
902 (u64
) sizeof(u64
), (u64
) &v
, 0, 0, NULL
);
903 if (salr
!= SN_HWPERF_OP_OK
) {
908 if ((sn_hwperf_salheap
= vmalloc(v
)) == NULL
) {
912 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
913 SN_HWPERF_INSTALL_HEAP
, 0, v
,
914 (u64
) sn_hwperf_salheap
, 0, 0, NULL
);
915 if (salr
!= SN_HWPERF_OP_OK
) {
920 salr
= ia64_sn_hwperf_op(sn_hwperf_master_nasid
,
921 SN_HWPERF_OBJECT_COUNT
, 0,
922 sizeof(u64
), (u64
) &v
, 0, 0, NULL
);
923 if (salr
!= SN_HWPERF_OP_OK
) {
927 sn_hwperf_obj_cnt
= (int)v
;
930 if (e
< 0 && sn_hwperf_salheap
) {
931 vfree(sn_hwperf_salheap
);
932 sn_hwperf_salheap
= NULL
;
933 sn_hwperf_obj_cnt
= 0;
935 mutex_unlock(&sn_hwperf_init_mutex
);
939 int sn_topology_open(struct inode
*inode
, struct file
*file
)
942 struct seq_file
*seq
;
943 struct sn_hwperf_object_info
*objbuf
;
946 if ((e
= sn_hwperf_enum_objects(&nobj
, &objbuf
)) == 0) {
947 e
= seq_open(file
, &sn_topology_seq_ops
);
948 seq
= file
->private_data
;
949 seq
->private = objbuf
;
955 int sn_topology_release(struct inode
*inode
, struct file
*file
)
957 struct seq_file
*seq
= file
->private_data
;
960 return seq_release(inode
, file
);
963 int sn_hwperf_get_nearest_node(cnodeid_t node
,
964 cnodeid_t
*near_mem_node
, cnodeid_t
*near_cpu_node
)
968 struct sn_hwperf_object_info
*objbuf
;
970 if ((e
= sn_hwperf_enum_objects(&nobj
, &objbuf
)) == 0) {
971 e
= sn_hwperf_get_nearest_node_objdata(objbuf
, nobj
,
972 node
, near_mem_node
, near_cpu_node
);
979 static int __devinit
sn_hwperf_misc_register_init(void)
983 if (!ia64_platform_is("sn2"))
989 * Register a dynamic misc device for hwperf ioctls. Platforms
990 * supporting hotplug will create /dev/sn_hwperf, else user
991 * can to look up the minor number in /proc/misc.
993 if ((e
= misc_register(&sn_hwperf_dev
)) != 0) {
994 printk(KERN_ERR
"sn_hwperf_misc_register_init: failed to "
995 "register misc device for \"%s\"\n", sn_hwperf_dev
.name
);
1001 device_initcall(sn_hwperf_misc_register_init
); /* after misc_init() */
1002 EXPORT_SYMBOL(sn_hwperf_get_nearest_node
);