aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2007-11-21 09:08:50 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:54:40 -0500
commitebb53d75657f86587ac8cf3e38ab0c860a8e3d4f (patch)
tree2b1d63cb8ee54b19589d6d13a693147001e642ad /net/core
parentde4d1db369785c29d68915edfee0cb70e8199f4c (diff)
[NET] proto: Use pcounters for the inuse field
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/sock.c61
1 files changed, 6 insertions, 55 deletions
diff --git a/net/core/sock.c b/net/core/sock.c
index c9305a8617..eac7aa0721 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1804,65 +1804,15 @@ EXPORT_SYMBOL(sk_common_release);
1804static DEFINE_RWLOCK(proto_list_lock); 1804static DEFINE_RWLOCK(proto_list_lock);
1805static LIST_HEAD(proto_list); 1805static LIST_HEAD(proto_list);
1806 1806
1807#ifdef CONFIG_SMP
1808/*
1809 * Define default functions to keep track of inuse sockets per protocol
1810 * Note that often used protocols use dedicated functions to get a speed increase.
1811 * (see DEFINE_PROTO_INUSE/REF_PROTO_INUSE)
1812 */
1813static void inuse_add(struct proto *prot, int inc)
1814{
1815 per_cpu_ptr(prot->inuse_ptr, smp_processor_id())[0] += inc;
1816}
1817
1818static int inuse_get(const struct proto *prot)
1819{
1820 int res = 0, cpu;
1821 for_each_possible_cpu(cpu)
1822 res += per_cpu_ptr(prot->inuse_ptr, cpu)[0];
1823 return res;
1824}
1825
1826static int inuse_init(struct proto *prot)
1827{
1828 if (!prot->inuse_getval || !prot->inuse_add) {
1829 prot->inuse_ptr = alloc_percpu(int);
1830 if (prot->inuse_ptr == NULL)
1831 return -ENOBUFS;
1832
1833 prot->inuse_getval = inuse_get;
1834 prot->inuse_add = inuse_add;
1835 }
1836 return 0;
1837}
1838
1839static void inuse_fini(struct proto *prot)
1840{
1841 if (prot->inuse_ptr != NULL) {
1842 free_percpu(prot->inuse_ptr);
1843 prot->inuse_ptr = NULL;
1844 prot->inuse_getval = NULL;
1845 prot->inuse_add = NULL;
1846 }
1847}
1848#else
1849static inline int inuse_init(struct proto *prot)
1850{
1851 return 0;
1852}
1853
1854static inline void inuse_fini(struct proto *prot)
1855{
1856}
1857#endif
1858
1859int proto_register(struct proto *prot, int alloc_slab) 1807int proto_register(struct proto *prot, int alloc_slab)
1860{ 1808{
1861 char *request_sock_slab_name = NULL; 1809 char *request_sock_slab_name = NULL;
1862 char *timewait_sock_slab_name; 1810 char *timewait_sock_slab_name;
1863 1811
1864 if (inuse_init(prot)) 1812 if (pcounter_alloc(&prot->inuse) != 0) {
1813 printk(KERN_CRIT "%s: Can't alloc inuse counters!\n", prot->name);
1865 goto out; 1814 goto out;
1815 }
1866 1816
1867 if (alloc_slab) { 1817 if (alloc_slab) {
1868 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0, 1818 prot->slab = kmem_cache_create(prot->name, prot->obj_size, 0,
@@ -1930,7 +1880,7 @@ out_free_sock_slab:
1930 kmem_cache_destroy(prot->slab); 1880 kmem_cache_destroy(prot->slab);
1931 prot->slab = NULL; 1881 prot->slab = NULL;
1932out_free_inuse: 1882out_free_inuse:
1933 inuse_fini(prot); 1883 pcounter_free(&prot->inuse);
1934out: 1884out:
1935 return -ENOBUFS; 1885 return -ENOBUFS;
1936} 1886}
@@ -1943,7 +1893,8 @@ void proto_unregister(struct proto *prot)
1943 list_del(&prot->node); 1893 list_del(&prot->node);
1944 write_unlock(&proto_list_lock); 1894 write_unlock(&proto_list_lock);
1945 1895
1946 inuse_fini(prot); 1896 pcounter_free(&prot->inuse);
1897
1947 if (prot->slab != NULL) { 1898 if (prot->slab != NULL) {
1948 kmem_cache_destroy(prot->slab); 1899 kmem_cache_destroy(prot->slab);
1949 prot->slab = NULL; 1900 prot->slab = NULL;