root/opal/mca/timer/altix/timer_altix_component.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. opal_timer_altix_open
  2. opal_timer_altix_close

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
   2 /*
   3  * Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
   4  *                         University Research and Technology
   5  *                         Corporation.  All rights reserved.
   6  * Copyright (c) 2004-2005 The University of Tennessee and The University
   7  *                         of Tennessee Research Foundation.  All rights
   8  *                         reserved.
   9  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
  10  *                         University of Stuttgart.  All rights reserved.
  11  * Copyright (c) 2004-2005 The Regents of the University of California.
  12  *                         All rights reserved.
  13  * Copyright (c) 2014      Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * Copyright (c) 2015      Los Alamos National Security, LLC. All rights
  16  *                         reserved.
  17  * $COPYRIGHT$
  18  *
  19  * Additional copyrights may follow
  20  *
  21  * $HEADER$
  22  */
  23 
  24 #include "opal_config.h"
  25 
  26 #include <sys/types.h>
  27 #include <sys/stat.h>
  28 #include <fcntl.h>
  29 #include <sys/ioctl.h>
  30 #include <sys/mman.h>
  31 #include <sn/mmtimer.h>
  32 #include <unistd.h>
  33 #include <errno.h>
  34 
  35 #include "opal/mca/timer/timer.h"
  36 #include "opal/mca/timer/altix/timer_altix.h"
  37 #include "opal/constants.h"
  38 #include "opal/util/sys_limits.h"
  39 
  40 opal_timer_t opal_timer_altix_freq;
  41 opal_timer_t opal_timer_altix_usec_conv;
  42 volatile unsigned long *opal_timer_altix_mmdev_timer_addr;
  43 static unsigned long *mmdev_map;
  44 
  45 static int opal_timer_altix_open(void);
  46 static int opal_timer_altix_close(void);
  47 
  48 const opal_timer_base_component_2_0_0_t mca_timer_altix_component = {
  49     /* First, the mca_component_t struct containing meta information
  50        about the component itself */
  51     .timerc_version = {
  52         OPAL_TIMER_BASE_VERSION_2_0_0,
  53 
  54         /* Component name and version */
  55         .mca_component_name = "altix",
  56         MCA_BASE_MAKE_VERSION(component, OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION,
  57                               OPAL_RELEASE_VERSION),
  58 
  59         /* Component open and close functions */
  60         .mca_open_component = opal_timer_altix_open,
  61         .mca_close_component = opal_timer_altix_close,
  62     },
  63     .timerc_data = {
  64         /* The component is checkpoint ready */
  65         MCA_BASE_METADATA_PARAM_CHECKPOINT
  66     },
  67 };
  68 
  69 
  70 static int
  71 opal_timer_altix_open(void)
  72 {
  73     int fd, ret;
  74     unsigned long val;
  75     long offset;
  76 
  77     fd = open(MMTIMER_FULLNAME, O_RDONLY);
  78     if (fd < 0) return OPAL_ERR_NOT_FOUND;
  79 
  80     /* make sure we can map the timer */
  81     ret = ioctl(fd, MMTIMER_MMAPAVAIL, 0);
  82     if (1 != ret) return OPAL_ERR_NOT_SUPPORTED;
  83 
  84     /* find the frequency */
  85     ret = ioctl(fd, MMTIMER_GETFREQ, &val);
  86     if (ret == -ENOSYS) return OPAL_ERR_NOT_SUPPORTED;
  87     opal_timer_altix_freq = val;
  88     opal_timer_altix_usec_conv = opal_timer_altix_freq / 1000000;
  89 
  90     /* find the address of the counter */
  91     ret = ioctl(fd, MMTIMER_GETOFFSET, 0);
  92     if (ret == -ENOSYS) return OPAL_ERR_NOT_SUPPORTED;
  93     offset = ret;
  94 
  95     mmdev_map = mmap(0, (size_t)opal_getpagesize(), PROT_READ, MAP_SHARED, fd, 0);
  96     if (NULL == mmdev_map) return OPAL_ERR_NOT_SUPPORTED;
  97     opal_timer_altix_mmdev_timer_addr = mmdev_map + offset;
  98     close(fd);
  99 
 100     return OPAL_SUCCESS;
 101 }
 102 
 103 
 104 static int
 105 opal_timer_altix_close(void)
 106 {
 107     if (NULL != mmdev_map) {
 108         munmap(mmdev_map, (size_t)opal_getpagesize());
 109     }
 110 
 111     return OPAL_SUCCESS;
 112 }

/* [<][>][^][v][top][bottom][index][help] */