summaryrefslogtreecommitdiff
path: root/CIAO/tests/DAnCE/LocalityManager/CPUAffinity/CPUAffinity_exec.cpp
blob: f6ef69a57f83d1b76ade96bb7bb5a5021fd0d36f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// -*- C++ -*-
#include "CPUAffinity_exec.h"
#include "ace/Log_Msg.h"
#include "ace/os_include/os_sched.h"
#include "tao/ORB_Core.h"
#include "tao/Transport_Cache_Manager.h"
#include "tao/Thread_Lane_Resources.h"

namespace CIAO_cpuaffinity_A_Impl
{
  //============================================================
  // Pulse generator
  //============================================================

  Component_exec_i::Component_exec_i  (void)
    : cpu_affinity_ (-1)
  {
  }

  Component_exec_i::~Component_exec_i  (void)
  {
  }

  // Port operations.
  void Component_exec_i::cpu_affinity (CORBA::Long tc_max)
  {
    this->cpu_affinity_ = tc_max;
  }

  CORBA::Long Component_exec_i::cpu_affinity (void)
  {
    return this->cpu_affinity_;
  }
  // Operations from Components::SessionComponent.
  void
  Component_exec_i::set_session_context (
    ::Components::SessionContext_ptr ctx)
  {
    this->context_ =
      ::cpuaffinity::CCM_A_Context::_narrow (ctx);

    if ( ::CORBA::is_nil (this->context_.in ()))
      {
        throw ::CORBA::INTERNAL ();
      }
  }

  void
  Component_exec_i::configuration_complete (void)
  {
  }

  void
  Component_exec_i::ccm_activate (void)
  {
#if defined (ACE_HAS_SCHED_GETAFFINITY)
    if (ACE_OS::num_processors () < 2)
      {
        ACE_DEBUG ((LM_DEBUG, "This machine only has a single processor, aborting\n"));
        return;
      }

    cpu_set_t mask;
    CPU_ZERO (&mask);

    int retval = sched_getaffinity (0, sizeof (cpu_set_t), &mask);

    if (retval != 0)
      {
        ACE_ERROR ((LM_ERROR, "Error: Non-zero return value from sched_getaffinity %p\n"));
        return;
      }

    int z_set = CPU_ISSET (0, &mask);
    int o_set = CPU_ISSET (1, &mask);

    if (cpu_affinity_ == 0 &&
        (!z_set || o_set))
      {
        ACE_ERROR ((LM_ERROR, "Error: Expected to only be on processor zero.\n"));
      }

    if (cpu_affinity_ == 1 &&
        (z_set || !o_set))
      {
        ACE_ERROR ((LM_ERROR, "Error: Expected to only be on processor one.\n"));
      }

    if (cpu_affinity_ > 1)
      {
        ACE_ERROR ((LM_ERROR, "Error: Trying to test an affinity I don't support\n"));
      }
#endif
  }

  void
  Component_exec_i::ccm_passivate (void)
  {
  }

  void
  Component_exec_i::ccm_remove (void)
  {
  }

  extern "C" COMMANDLINEPASSAGE_EXEC_Export ::Components::EnterpriseComponent_ptr
  create_Component_Impl (void)
  {
    ::Components::EnterpriseComponent_ptr retval =
      ::Components::EnterpriseComponent::_nil ();

    ACE_NEW_NORETURN (
      retval,
      Component_exec_i );

    return retval;
  }
}