mem_refcnt.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:6k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: mem_refcnt.c,v 1.1 2002/02/28 17:31:25 marcelo Exp $
  2.  *
  3.  * This file is subject to the terms and conditions of the GNU General Public
  4.  * License.  See the file "COPYING" in the main directory of this archive
  5.  * for more details.
  6.  *
  7.  * Copyright (C) 1992 - 1997, 2000-2002 Silicon Graphics, Inc. All rights reserved.
  8.  */
  9. #include <linux/config.h>
  10. #include <linux/types.h>
  11. #include <asm/sn/arch.h>
  12. #include <asm/sn/sgi.h>
  13. #include <asm/sn/io.h>
  14. #include <asm/sn/sn_cpuid.h>
  15. #include <asm/sn/invent.h>
  16. #include <asm/sn/hcl.h>
  17. #include <asm/sn/hcl_util.h>
  18. #include <asm/sn/nodepda.h>
  19. #include <asm/sn/iograph.h>
  20. #include <asm/sn/sn1/mem_refcnt.h>
  21. #include <asm/sn/sn1/hwcntrs.h>
  22. #include <asm/sn/sn1/hubspc.h>
  23. // From numa_hw.h
  24. #define MIGR_COUNTER_MAX_GET(nodeid) 
  25.         (NODEPDA_MCD((nodeid))->migr_system_kparms.migr_threshold_reference)
  26. /*
  27.  * Get the Absolute Theshold
  28.  */
  29. #define MIGR_THRESHOLD_ABS_GET(nodeid) ( 
  30.         MD_MIG_VALUE_THRESH_GET(COMPACT_TO_NASID_NODEID(nodeid)))
  31. /*
  32.  * Get the current Differential Threshold
  33.  */
  34. #define MIGR_THRESHOLD_DIFF_GET(nodeid) 
  35.         (NODEPDA_MCD(nodeid)->migr_as_kparms.migr_base_threshold)
  36. #define NUM_OF_HW_PAGES_PER_SW_PAGE()   (NBPP / MD_PAGE_SIZE)
  37. // #include "migr_control.h"
  38. int
  39. mem_refcnt_attach(devfs_handle_t hub)
  40. {
  41. #ifndef CONFIG_IA64_SGI_SN
  42.         devfs_handle_t refcnt_dev;
  43.         
  44.         hwgraph_char_device_add(hub,
  45.                                 "refcnt",
  46.                                 "hubspc_", 
  47. &refcnt_dev);
  48.         device_info_set(refcnt_dev, (void*)(ulong)HUBSPC_REFCOUNTERS);
  49. #endif
  50.         return (0);
  51. }
  52. /*ARGSUSED*/
  53. int
  54. mem_refcnt_open(devfs_handle_t *devp, mode_t oflag, int otyp, cred_t *crp)
  55. {
  56.         cnodeid_t node;
  57.         node = master_node_get(*devp);
  58.         ASSERT( (node >= 0) && (node < numnodes) );
  59.         if (NODEPDA(node)->migr_refcnt_counterbuffer == NULL) {
  60.                 return (ENODEV);
  61.         }
  62.         ASSERT( NODEPDA(node)->migr_refcnt_counterbase != NULL );
  63.         ASSERT( NODEPDA(node)->migr_refcnt_cbsize != (size_t)0 );
  64.         return (0);
  65. }
  66. /*ARGSUSED*/
  67. int
  68. mem_refcnt_close(devfs_handle_t dev, int oflag, int otyp, cred_t *crp)
  69. {
  70.         return 0;
  71. }
  72. /*ARGSUSED*/
  73. int
  74. mem_refcnt_mmap(devfs_handle_t dev, vhandl_t *vt, off_t off, size_t len, uint prot)
  75. {
  76.         cnodeid_t node;
  77.         int errcode;
  78.         char* buffer;
  79.         size_t blen;
  80.         
  81.         node = master_node_get(dev);
  82.         ASSERT( (node >= 0) && (node < numnodes) );
  83.         ASSERT( NODEPDA(node)->migr_refcnt_counterbuffer != NULL);
  84.         ASSERT( NODEPDA(node)->migr_refcnt_counterbase != NULL );
  85.         ASSERT( NODEPDA(node)->migr_refcnt_cbsize != 0 );
  86.         /*
  87.          * XXXX deal with prot's somewhere around here....
  88.          */
  89.         buffer = NODEPDA(node)->migr_refcnt_counterbuffer;
  90.         blen = NODEPDA(node)->migr_refcnt_cbsize;
  91.         /*
  92.          * Force offset to be a multiple of sizeof(refcnt_t)
  93.          * We round up.
  94.          */
  95.         off = (((off - 1)/sizeof(refcnt_t)) + 1) * sizeof(refcnt_t);
  96.         if ( ((buffer + blen) - (buffer + off + len)) < 0 ) {
  97.                 return (EPERM);
  98.         }
  99.         errcode = v_mapphys(vt,
  100.                             buffer + off,
  101.                             len);
  102.         return errcode;
  103. }
  104. /*ARGSUSED*/
  105. int
  106. mem_refcnt_unmap(devfs_handle_t dev, vhandl_t *vt)
  107. {
  108.         return 0;
  109. }
  110. /* ARGSUSED */
  111. int
  112. mem_refcnt_ioctl(devfs_handle_t dev,
  113.                  int cmd,
  114.                  void *arg,
  115.                  int mode,
  116.                  cred_t *cred_p,
  117.                  int *rvalp)
  118. {
  119.         cnodeid_t node;
  120.         int errcode;
  121. extern int numnodes;
  122.         
  123.         node = master_node_get(dev);
  124.         ASSERT( (node >= 0) && (node < numnodes) );
  125.         ASSERT( NODEPDA(node)->migr_refcnt_counterbuffer != NULL);
  126.         ASSERT( NODEPDA(node)->migr_refcnt_counterbase != NULL );
  127.         ASSERT( NODEPDA(node)->migr_refcnt_cbsize != 0 );
  128.         errcode = 0;
  129.         
  130.         switch (cmd) {
  131.         case RCB_INFO_GET:
  132.         {
  133.                 rcb_info_t rcb;
  134.                 
  135.                 rcb.rcb_len = NODEPDA(node)->migr_refcnt_cbsize;
  136.                 
  137.                 rcb.rcb_sw_sets = NODEPDA(node)->migr_refcnt_numsets;
  138.                 rcb.rcb_sw_counters_per_set = numnodes;
  139.                 rcb.rcb_sw_counter_size = sizeof(refcnt_t);
  140.                 rcb.rcb_base_pages = NODEPDA(node)->migr_refcnt_numsets /
  141.                                      NUM_OF_HW_PAGES_PER_SW_PAGE();  
  142.                 rcb.rcb_base_page_size = NBPP;
  143.                 rcb.rcb_base_paddr = ctob(slot_getbasepfn(node, 0));
  144.                 
  145.                 rcb.rcb_cnodeid = node;
  146.                 rcb.rcb_granularity = MD_PAGE_SIZE;
  147. #ifdef LATER
  148.                 rcb.rcb_hw_counter_max = MIGR_COUNTER_MAX_GET(node);
  149.                 rcb.rcb_diff_threshold = MIGR_THRESHOLD_DIFF_GET(node);
  150. #endif
  151.                 rcb.rcb_abs_threshold = MIGR_THRESHOLD_ABS_GET(node);
  152.                 rcb.rcb_num_slots = MAX_MEM_SLOTS;
  153.                 if (COPYOUT(&rcb, arg, sizeof(rcb_info_t))) {
  154.                         errcode = EFAULT;
  155.                 }
  156.                 break;
  157.         }
  158.         case RCB_SLOT_GET:
  159.         {
  160.                 rcb_slot_t slot[MAX_MEM_SLOTS];
  161.                 int s;
  162.                 int nslots;
  163.                 nslots = MAX_MEM_SLOTS;
  164.                 ASSERT(nslots <= MAX_MEM_SLOTS);
  165.                 for (s = 0; s < nslots; s++) {
  166.                         slot[s].base = (uint64_t)ctob(slot_getbasepfn(node, s));
  167. #ifdef LATER
  168.                         slot[s].size  = (uint64_t)ctob(slot_getsize(node, s));
  169. #else
  170.                         slot[s].size  = (uint64_t)1;
  171. #endif
  172.                 }
  173.                 if (COPYOUT(&slot[0], arg, nslots * sizeof(rcb_slot_t))) {
  174.                         errcode = EFAULT;
  175.                 }
  176.                 
  177.                 *rvalp = nslots;
  178.                 break;
  179.         }
  180.                 
  181.         default:
  182.                 errcode = EINVAL;
  183.                 break;
  184.         }
  185.         
  186.         return errcode;
  187. }