Change Networking mibs to use kmalloc_percpu -- 3/3

Change Networking mibs to use kmalloc_percpu -- 3/3

Post by Ravikiran G Thirumala » Thu, 05 Dec 2002 14:50:10



This patch is 3 of 3

D: Name: sctpmibs-2.5.50-1.patch
D: Author: Ravikiran Thirumalai
D: Description: Changes sctp stats to use kmalloc_percpu from the traditional
D:              padded NR_CPUS arrays

 include/net/sctp/sctp.h |    2 +-
 net/sctp/protocol.c     |   44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff -ruN -X dontdiff linux-2.5.50/include/net/sctp/sctp.h mibstats-2.5.50/include/net/sctp/sctp.h
--- linux-2.5.50/include/net/sctp/sctp.h        Thu Nov 28 04:05:53 2002

 #define SCTP_SOCK_SLEEP_POST(sk) SOCK_SLEEP_POST(sk)

 /* SCTP SNMP MIB stats handlers */
-extern struct sctp_mib sctp_statistics[NR_CPUS * 2];
+DECLARE_SNMP_STAT(struct sctp_mib, sctp_statistics);
 #define SCTP_INC_STATS(field)          SNMP_INC_STATS(sctp_statistics, field)
 #define SCTP_INC_STATS_BH(field)       SNMP_INC_STATS_BH(sctp_statistics, field)
 #define SCTP_INC_STATS_USER(field)     SNMP_INC_STATS_USER(sctp_statistics, field)
diff -ruN -X dontdiff linux-2.5.50/net/sctp/protocol.c mibstats-2.5.50/net/sctp/protocol.c
--- linux-2.5.50/net/sctp/protocol.c    Thu Nov 28 04:06:05 2002

 /* Global data structures. */
 sctp_protocol_t sctp_proto;
 struct proc_dir_entry  *proc_net_sctp;
-struct sctp_mib sctp_statistics[NR_CPUS * 2];
+DEFINE_SNMP_STAT(struct sctp_mib, sctp_statistics);

 /* This is the global socket data structure used for responding to

        }
 }

+static int __init init_sctp_mibs(void)
+{
+       int i;
+      
+       sctp_statistics[0] = kmalloc_percpu(sizeof (struct sctp_mib),
+                                           GFP_KERNEL);
+       if (!sctp_statistics[0])
+               return -ENOMEM;
+       sctp_statistics[1] = kmalloc_percpu(sizeof (struct sctp_mib),
+                                           GFP_KERNEL);
+       if (!sctp_statistics[1]) {
+               kfree_percpu(sctp_statistics[0]);
+               return -ENOMEM;
+       }
+
+       /* Zero all percpu versions of the mibs */
+       for (i = 0; i < NR_CPUS; i++) {
+               if (cpu_possible(i)) {
+                       memset(per_cpu_ptr(sctp_statistics[0], i), 0,
+                                       sizeof (struct sctp_mib));
+                       memset(per_cpu_ptr(sctp_statistics[1], i), 0,
+                                       sizeof (struct sctp_mib));
+               }
+       }
+       return 0;
+      
+}
+
+static void cleanup_sctp_mibs(void)
+{
+       kfree_percpu(sctp_statistics[0]);
+       kfree_percpu(sctp_statistics[1]);
+}
+
 /* Initialize the universe into something sensible.  */
 int sctp_init(void)

        /* Add SCTP to inetsw linked list.  */
        inet_register_protosw(&sctp_protosw);

+       /* Allocate and initialise sctp mibs.  */
+       status = init_sctp_mibs();
+       if (status)
+               goto err_init_mibs;
+              
        /* Initialize proc fs directory.  */
        sctp_proc_init();

 err_ahash_alloc:
        sctp_dbg_objcnt_exit();
        sctp_proc_exit();
+       cleanup_sctp_mibs();
+err_init_mibs:
        inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
        inet_unregister_protosw(&sctp_protosw);

        sctp_dbg_objcnt_exit();
        sctp_proc_exit();
+       cleanup_sctp_mibs();

        inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
        inet_unregister_protosw(&sctp_protosw);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in

More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/