File: solaris-memory.c

package info (click to toggle)
papi 5.7.0+dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 9,856 kB
  • sloc: ansic: 93,265; fortran: 3,338; xml: 2,460; makefile: 815; sh: 290
file content (194 lines) | stat: -rw-r--r-- 5,273 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*
* File:    solaris-memory.c
* Author:  Kevin London
*          london@cs.utk.edu
*
* Mods:    Philip J. Mucci
*          mucci@cs.utk.edu
*
* Mods:    Vince Weaver
*          vweaver1@eecs.utk.edu
*
* Mods:    Fabian Gorsler 
*          fabian.gorsler@smail.inf.h-bonn-rhein-sieg.de
*/

#include "papi.h"
#include "papi_internal.h"


int
_solaris_get_memory_info( PAPI_hw_info_t * hw, int id )
{
        FILE *pipe;
        char line[BUFSIZ];

	PAPI_mh_level_t *mem = hw->mem_hierarchy.level;

	pipe=popen("prtconf -pv","r");
        if (pipe==NULL) {
	   return PAPI_ESYS;
	}

	while(1) {

	   if (fgets(line,BUFSIZ,pipe)==NULL) break;

           if (strstr(line,"icache-size:")) {
	      sscanf(line,"%*s %#x",&mem[0].cache[0].size);
	   }
           if (strstr(line,"icache-line-size:")) {
	      sscanf(line,"%*s %#x",&mem[0].cache[0].line_size);
	   }
           if (strstr(line,"icache-associativity:")) {
	      sscanf(line,"%*s %#x",&mem[0].cache[0].associativity);
	   }

           if (strstr(line,"dcache-size:")) {
	      sscanf(line,"%*s %#x",&mem[0].cache[1].size);
	   }
           if (strstr(line,"dcache-line-size:")) {
	      sscanf(line,"%*s %#x",&mem[0].cache[1].line_size);
	   }
           if (strstr(line,"dcache-associativity:")) {
	      sscanf(line,"%*s %#x",&mem[0].cache[1].associativity);
	   }

           if (strstr(line,"ecache-size:")) {
	      sscanf(line,"%*s %#x",&mem[1].cache[0].size);
	   }
           if (strstr(line,"ecache-line-size:")) {
	      sscanf(line,"%*s %#x",&mem[1].cache[0].line_size);
	   }
           if (strstr(line,"ecache-associativity:")) {
	      sscanf(line,"%*s %#x",&mem[1].cache[0].associativity);
	   }

           if (strstr(line,"#itlb-entries:")) {
	      sscanf(line,"%*s %#x",&mem[0].tlb[0].num_entries);
	   }
           if (strstr(line,"#dtlb-entries:")) {
	      sscanf(line,"%*s %#x",&mem[0].tlb[1].num_entries);
	   }

	}
       

        pclose(pipe);

	/* I-Cache -> L1$ instruction */
	mem[0].cache[0].type = PAPI_MH_TYPE_INST;
	if (mem[0].cache[0].line_size!=0) mem[0].cache[0].num_lines =
		mem[0].cache[0].size / mem[0].cache[0].line_size;

	/* D-Cache -> L1$ data */
	mem[0].cache[1].type =
		PAPI_MH_TYPE_DATA | PAPI_MH_TYPE_WT | PAPI_MH_TYPE_LRU;
	if (mem[0].cache[1].line_size!=0) mem[0].cache[1].num_lines =
		mem[0].cache[1].size / mem[0].cache[1].line_size;


	/* ITLB -> TLB instruction */
	mem[0].tlb[0].type = PAPI_MH_TYPE_INST | PAPI_MH_TYPE_PSEUDO_LRU;
        /* assume fully associative */
	mem[0].tlb[0].associativity = mem[0].tlb[0].num_entries;

	/* DTLB -> TLB data */
	mem[0].tlb[1].type = PAPI_MH_TYPE_DATA | PAPI_MH_TYPE_PSEUDO_LRU;
        /* assume fully associative */
	mem[0].tlb[1].associativity = mem[0].tlb[1].num_entries;

	/* L2$ unified */
	mem[1].cache[0].type = PAPI_MH_TYPE_UNIFIED | PAPI_MH_TYPE_WB
		| PAPI_MH_TYPE_PSEUDO_LRU;
	if (mem[1].cache[0].line_size!=0) mem[1].cache[0].num_lines =
		mem[1].cache[0].size / mem[1].cache[0].line_size;

	/* Indicate we have two levels filled in the hierarchy */
	hw->mem_hierarchy.levels = 2;

	return PAPI_OK;
}




int
_solaris_get_dmem_info( PAPI_dmem_info_t * d )
{

	FILE *fd;
	struct psinfo psi;

	if ( ( fd = fopen( "/proc/self/psinfo", "r" ) ) == NULL ) {
		SUBDBG( "fopen(/proc/self) errno %d", errno );
		return ( PAPI_ESYS );
	}

	fread( ( void * ) &psi, sizeof ( struct psinfo ), 1, fd );
	fclose( fd );

	d->pagesize = sysconf( _SC_PAGESIZE );
	d->size = d->pagesize * sysconf( _SC_PHYS_PAGES );
	d->resident = ( ( 1024 * psi.pr_size ) / d->pagesize );
	d->high_water_mark = PAPI_EINVAL;
	d->shared = PAPI_EINVAL;
	d->text = PAPI_EINVAL;
	d->library = PAPI_EINVAL;
	d->heap = PAPI_EINVAL;
	d->locked = PAPI_EINVAL;
	d->stack = PAPI_EINVAL;

	return PAPI_OK;

}

int
_niagara2_get_memory_info( PAPI_hw_info_t * hw, int id )
{
	PAPI_mh_level_t *mem = hw->mem_hierarchy.level;


	/* I-Cache -> L1$ instruction */
	/* FIXME: The policy used at this cache is unknown to PAPI. LSFR with random
	   replacement. */
	mem[0].cache[0].type = PAPI_MH_TYPE_INST;
	mem[0].cache[0].size = 16 * 1024;	// 16 Kb
	mem[0].cache[0].line_size = 32;
	mem[0].cache[0].num_lines =
		mem[0].cache[0].size / mem[0].cache[0].line_size;
	mem[0].cache[0].associativity = 8;

	/* D-Cache -> L1$ data */
	mem[0].cache[1].type =
		PAPI_MH_TYPE_DATA | PAPI_MH_TYPE_WT | PAPI_MH_TYPE_LRU;
	mem[0].cache[1].size = 8 * 1024;	// 8 Kb
	mem[0].cache[1].line_size = 16;
	mem[0].cache[1].num_lines =
		mem[0].cache[1].size / mem[0].cache[1].line_size;
	mem[0].cache[1].associativity = 4;

	/* ITLB -> TLB instruction */
	mem[0].tlb[0].type = PAPI_MH_TYPE_INST | PAPI_MH_TYPE_PSEUDO_LRU;
	mem[0].tlb[0].num_entries = 64;
	mem[0].tlb[0].associativity = 64;

	/* DTLB -> TLB data */
	mem[0].tlb[1].type = PAPI_MH_TYPE_DATA | PAPI_MH_TYPE_PSEUDO_LRU;
	mem[0].tlb[1].num_entries = 128;
	mem[0].tlb[1].associativity = 128;

	/* L2$ unified */
	mem[1].cache[0].type = PAPI_MH_TYPE_UNIFIED | PAPI_MH_TYPE_WB
		| PAPI_MH_TYPE_PSEUDO_LRU;
	mem[1].cache[0].size = 4 * 1024 * 1024;	// 4 Mb
	mem[1].cache[0].line_size = 64;
	mem[1].cache[0].num_lines =
		mem[1].cache[0].size / mem[1].cache[0].line_size;
	mem[1].cache[0].associativity = 16;

	/* Indicate we have two levels filled in the hierarchy */
	hw->mem_hierarchy.levels = 2;

	return PAPI_OK;
}