*
* RETURNS:
* 1 if stats have been sucessfully read, or 0 otherwise.
+ * Returns -1 if the buffer was too small and needs to be reallocated.
***************************************************************************
*/
int read_softnet(struct stats_softnet *st_softnet, __nr_t nr_alloc,
FILE *fp;
struct stats_softnet *st_softnet_i;
char line[1024];
- int cpu;
+ int cpu = 1, rc = 1;
/* Open /proc/net/softnet_stat file */
if ((fp = fopen(NET_SOFTNET, "r")) == NULL)
return 0;
- for (cpu = 1; cpu < nr_alloc; cpu++) {
- if (!(online_cpu_bitmap[(cpu - 1) >> 3] & (1 << ((cpu - 1) & 0x07))))
- /* CPU is offline */
- continue;
+ while (fgets(line, sizeof(line), fp) != NULL) {
+
+ while ((!(online_cpu_bitmap[(cpu - 1) >> 3] & (1 << ((cpu - 1) & 0x07)))) && (cpu <= NR_CPUS + 1)) {
+ cpu++;
+ }
+ if (cpu > NR_CPUS + 1)
+ /* Should never happen */
+ return 0;
- if (fgets(line, sizeof(line), fp) == NULL)
+ if (cpu + 1 > nr_alloc) {
+ rc = -1;
break;
+ }
- st_softnet_i = st_softnet + cpu;
+ st_softnet_i = st_softnet + cpu++;
sscanf(line, "%x %x %x %*x %*x %*x %*x %*x %*x %x %x",
&st_softnet_i->processed,
&st_softnet_i->dropped,
}
fclose(fp);
- return 1;
+ return rc;
}
/*
* CPU bitmap which has been filled.
*
* RETURNS:
- * Number of CPU for which statistics have to be be read.
+ * Number of CPU for which statistics have to be read.
* 1 means CPU "all", 2 means CPU "all" and CPU 0, etc.
* Or -1 if the buffer was too small and needs to be reallocated.
***************************************************************************
/* Get online CPU list */
nr_read = get_online_cpu_list(online_cpu_bitmap, bitmap_size);
- if (!nr_read)
- break;
+
+ if (nr_read > 0) {
+ /* Read /proc/net/softnet stats */
+ nr_read *= read_softnet(st_softnet, a->nr_allocated, online_cpu_bitmap);
+ }
if (nr_read < 0) {
/* Buffer needs to be reallocated */
st_softnet = (struct stats_softnet *) reallocate_buffer(a);
}
- else {
- if (!read_softnet(st_softnet, a->nr_allocated, online_cpu_bitmap)) {
- /* File /proc/net/softnet doesn't exist */
- nr_read = 0;
- }
- }
}
while (nr_read < 0);