Esempio n. 1
0
void PLEN2::Soul::m_preprocess()
{
    #if DEBUG
        PROFILING("Soul::m_preprocess()");
    #endif


    if (m_log_count >= (GETUP_WAIT_MSEC / SAMPLING_INTERVAL_MSEC))
    {
        Shared::acc_backup[X_AXIS] /= m_log_count;
        Shared::acc_backup[Y_AXIS] /= m_log_count;
        Shared::acc_backup[Z_AXIS] /= m_log_count;

        if (   (abs(Shared::acc_backup[Y_AXIS]) > abs(Shared::acc_backup[X_AXIS]))
            && (abs(Shared::acc_backup[Y_AXIS]) > abs(Shared::acc_backup[Z_AXIS]))
            && (abs(Shared::acc_backup[Y_AXIS]) > GRAVITY_AXIS_THRESHOLD) )
        {
            System::debugSerial().println(F("status: lying"));

            m_lying = true;
        }
        else
        {
            Shared::acc_backup[X_AXIS] = 0;
            Shared::acc_backup[Y_AXIS] = 0;
            Shared::acc_backup[Z_AXIS] = 0;
        }

        m_log_count = 0;
    }
}
Esempio n. 2
0
bool PLEN2::JointController::setAngleDiff(uint8_t joint_id, int16_t angle_diff)
{
    #if DEBUG_HARD
        PROFILING("JointController::setAngleDiff()");
    #endif


    if (joint_id >= JOINTS_SUM)
    {
        #if DEBUG_HARD
            System::debugSerial().print(F(">>> bad argment! : joint_id = "));
            System::debugSerial().println(static_cast<int>(joint_id));
        #endif

        return false;
    }


    int16_t angle = constrain(
        angle_diff + m_SETTINGS[joint_id].HOME,
        m_SETTINGS[joint_id].MIN, m_SETTINGS[joint_id].MAX
    );

    m_pwms[joint_id] = map(angle, ANGLE_MIN, ANGLE_MAX,
        #if CLOCK_WISE
            PWM_MIN, PWM_MAX
        #else
            PWM_MAX, PWM_MIN
        #endif
    );

    return true;
}
Esempio n. 3
0
void PLEN2::JointController::resetSettings()
{
    #if DEBUG
        PROFILING("JointController::resetSettings()");
    #endif


    EEPROM[INIT_FLAG_ADDRESS] = INIT_FLAG_VALUE;
    eeprom_busy_wait();

    for (uint8_t index = 0; index < sizeof(Shared::m_SETTINGS_INITIAL); index++)
    {
        EEPROM[SETTINGS_HEAD_ADDRESS + index] = pgm_read_byte(
            reinterpret_cast<const uint8_t*>(Shared::m_SETTINGS_INITIAL) + index
        );
        eeprom_busy_wait();
    }

    for (uint8_t joint_id = 0; joint_id < JOINTS_SUM; joint_id++)
    {
        m_SETTINGS[joint_id].MIN  = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 0);
        m_SETTINGS[joint_id].MAX  = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 1);
        m_SETTINGS[joint_id].HOME = pgm_read_word(Shared::m_SETTINGS_INITIAL + joint_id * 3 + 2);

        setAngle(joint_id, m_SETTINGS[joint_id].HOME);
    }
}
void PLEN2::JointController::loadSettings()
{
    #if DEBUG
        PROFILING("JointController::loadSettings()");
    #endif


    uint8_t* filler = reinterpret_cast<uint8_t*>(m_SETTINGS);
    
    if (EEPROM[INIT_FLAG_ADDRESS] != INIT_FLAG_VALUE)
    {
        EEPROM[INIT_FLAG_ADDRESS] = INIT_FLAG_VALUE;
        eeprom_busy_wait();

        for (uint8_t index = 0; index < sizeof(m_SETTINGS); index++)
        {
            EEPROM[SETTINGS_HEAD_ADDRESS + index] = filler[index];
            eeprom_busy_wait();
        }
    }
    else
    {
        for (uint8_t index = 0; index < sizeof(m_SETTINGS); index++)
        {
            filler[index] = EEPROM[SETTINGS_HEAD_ADDRESS + index];
        }
    }

    for (uint8_t joint_id = 0; joint_id < JOINTS_SUM; joint_id++)
    {
        setAngle(joint_id, m_SETTINGS[joint_id].HOME);
    }

    /*
        @brief Configure timer 1

        @attention
        It might be easy to understand compare-matched output is LOW,
        but in that case, PWM is outputting at switching multiplexer's output,
        so the signal gets an impulse noise.
    */
    cli();

    TCCR1A =
        _BV(WGM11)  | _BV(WGM10)  | // Set mode to "10bit fast PWM".
        _BV(COM1A1) | _BV(COM1A0) | // Set OC1A to HIGH when compare matched.
        _BV(COM1B1) | _BV(COM1B0) | // Set OC1B to HIGH when compare matched.
        _BV(COM1C1) | _BV(COM1C0);  // Set OC1C to HIGH when compare matched.

    TCCR1B = 
        _BV(WGM12) |                // Set mode to "10bit fast PWM".
        _BV(CS11)  | _BV(CS10);     // Set prescaler to 64.

    TIFR1 = _BV(OCF1A) | _BV(OCF1B) | _BV(OCF1C) | _BV(TOV1); // Clearing interruption flag.

    sei();

    TIMSK1 = _BV(TOIE1); // Begin timer 1.
}
Esempio n. 5
0
void PLEN2::Soul::userActionInputed()
{
    #if DEBUG
        PROFILING("Soul::userActionInputed()");
    #endif


    m_before_user_action_msec = millis();
}
Esempio n. 6
0
	void Octree::Traverse(Key _uModeNameKey, OctreeNodePtrVecRef _rvNodes, OctreeObjectPtrVecRef _rvObjects, OctreeNodePtr _pStartingNode)
	{
		PROFILING(__FUNCTION__);
		OctreeTraverseFuncMap::iterator iPair = m_mTraverseModes.find(_uModeNameKey);
		bool bResult = (m_mTraverseModes.end() != iPair);
		if (false != bResult)
		{
			OctreeTraverseFuncRef rFunc = iPair->second;
			_pStartingNode = (NULL == _pStartingNode) ? m_pRoot : _pStartingNode;
			//_pStartingNode->Traverse(rFunc, _rvNodes, _rvObjects);
			_pStartingNode->TraverseNoRecursion(rFunc, _rvNodes, _rvObjects);
		}
	}
Esempio n. 7
0
void PLEN2::Soul::action()
{
    #if DEBUG
        PROFILING("Soul::action()");
    #endif


    if (m_lying)
    {
        if (Shared::acc_backup[Y_AXIS] < 0)
        {
            #if TARGET_PLEN20
                m_motion_ctrl_ptr->play(SLOT_GETUP_FACE_DOWN);
            #endif

            #if TARGET_PLEN14
                m_motion_ctrl_ptr->play(SLOT_GETUP_FACE_UP);
            #endif
        }
        else
        {
            #if TARGET_PLEN20
                m_motion_ctrl_ptr->play(SLOT_GETUP_FACE_UP);
            #endif

            #if TARGET_PLEN14
                m_motion_ctrl_ptr->play(SLOT_GETUP_FACE_DOWN);
            #endif
        }

        m_lying = false;

        Shared::acc_backup[X_AXIS] = 0;
        Shared::acc_backup[Y_AXIS] = 0;
        Shared::acc_backup[Z_AXIS] = 0;

        return;
    }

    if (millis() - m_before_user_action_msec > m_action_interval)
    {
        m_motion_ctrl_ptr->play( random(MOTIONS_SLOT_BEGIN, MOTIONS_SLOT_END) );

        m_before_user_action_msec = millis();
        m_action_interval = BASE_INTERVAL_MSEC + random(RANDOM_INTERVAL_MSEC);
    }
}
Esempio n. 8
0
bool PLEN2::JointController::setHomeAngle(uint8_t joint_id, int16_t angle)
{
    #if DEBUG
        PROFILING("JointController::setHomeAngle()");
    #endif


    if (joint_id >= JOINTS_SUM)
    {
        #if DEBUG
            System::debugSerial().print(F(">>> bad argment! : joint_id = "));
            System::debugSerial().println(static_cast<int>(joint_id));
        #endif

        return false;
    }

    if (   (angle < m_SETTINGS[joint_id].MIN)
        || (angle > m_SETTINGS[joint_id].MAX) )
    {
        #if DEBUG
            System::debugSerial().print(F(">>> bad argment! : angle = "));
            System::debugSerial().println(angle);
        #endif

        return false;
    }


    m_SETTINGS[joint_id].HOME = angle;

    uint8_t* filler = reinterpret_cast<uint8_t*>(&(m_SETTINGS[joint_id].HOME));
    uint16_t address_offset = reinterpret_cast<uint16_t>(filler) - reinterpret_cast<uint16_t>(m_SETTINGS);

    #if DEBUG
        System::debugSerial().print(F(">>> address_offset : "));
        System::debugSerial().println(address_offset);
    #endif

    for (uint8_t index = 0; index < sizeof(m_SETTINGS[joint_id].HOME); index++)
    {
        EEPROM[SETTINGS_HEAD_ADDRESS + address_offset + index] = filler[index];
        eeprom_busy_wait();
    }

    return true;
}
Esempio n. 9
0
int8_t PLEN2::ExternalSD::writeSlot(uint32_t slot, const uint8_t data[], uint8_t write_size)
{
    uint32_t block;
    uint16_t offset;

    #if DEBUG
        PROFILING("ExternalSD::writeSlot()");
    #endif


    if (   (slot >= SLOT_END)
        || (write_size > SLOT_SIZE)
    )
    {
        #if DEBUG
            System::debugSerial().print(F(">>> bad argument! : slot = "));
            System::debugSerial().print(slot);
            System::debugSerial().print(F(", or write_size = "));
            System::debugSerial().println(write_size);
        #endif

        return -1;
    }

    block  = 32 + (slot * CHUNK_SIZE) / 512;
    offset = (slot * CHUNK_SIZE) % 512;

    #if DEBUG
        System::debugSerial().print(F("writeSlot slot = "));
        System::debugSerial().print(slot);
        System::debugSerial().print(F(", block = "));
        System::debugSerial().print(block);
        System::debugSerial().print(F(", offset = "));
        System::debugSerial().println(offset);
    #endif

    if (cacheRawBlock(block, CACHE_FOR_WRITE)) {
        memcpy(&mCacheBuf[offset], data, write_size);
        cacheFlush();
        return 0;
    }

    return -1;
}
Esempio n. 10
0
int8_t PLEN2::ExternalSD::readSlot(uint32_t slot, uint8_t data[], uint8_t read_size)
{
    uint32_t block;
    uint16_t offset;

    #if DEBUG
        PROFILING("ExternalSD::readSlot()");
    #endif


    if (   (slot >= SLOT_END)
        || (read_size > SLOT_SIZE)
    )
    {
        #if DEBUG
            System::debugSerial().print(F(">>> bad argument! : slot = "));
            System::debugSerial().print(slot);
            System::debugSerial().print(F(", or read_size = "));
            System::debugSerial().println(read_size);
        #endif

        return -1;
    }

    block  = 32 + (slot * CHUNK_SIZE) / 512;
    offset = (slot * CHUNK_SIZE) % 512;

    #if DEBUG
        System::debugSerial().print(F("readSlot slot = "));
        System::debugSerial().print(slot);
        System::debugSerial().print(F(", block = "));
        System::debugSerial().print(block);
        System::debugSerial().print(F(", offset = "));
        System::debugSerial().println(offset);
    #endif

    if (cacheRawBlock(block, CACHE_FOR_READ)) {
        memcpy(data, &mCacheBuf[offset], read_size);
        return read_size;
    }

    return -1;
}
Esempio n. 11
0
const int16_t& PLEN2::JointController::getHomeAngle(uint8_t joint_id)
{
    #if DEBUG
        PROFILING("JointController::getHomeAngle()");
    #endif


    if (joint_id >= JOINTS_SUM)
    {
        #if DEBUG
            System::debugSerial().print(F(">>> bad argment! : joint_id = "));
            System::debugSerial().println(static_cast<int>(joint_id));
        #endif

        return Shared::ERROR_LVALUE;
    }

    return m_SETTINGS[joint_id].HOME;
}
Esempio n. 12
0
void PLEN2::JointController::dump()
{
    #if DEBUG
        PROFILING("JointController::dump()");
    #endif


    System::outputSerial().println(F("["));

    for (uint8_t joint_id = 0; joint_id < JOINTS_SUM; joint_id++)
    {
        System::outputSerial().println(F("\t{"));

        System::outputSerial().print(F("\t\t\"@device\": "));
        System::outputSerial().print(static_cast<int>(joint_id));
        System::outputSerial().println(F(","));

        System::outputSerial().print(F("\t\t\"max\": "));
        System::outputSerial().print(m_SETTINGS[joint_id].MAX);
        System::outputSerial().println(F(","));

        System::outputSerial().print(F("\t\t\"min\": "));
        System::outputSerial().print(m_SETTINGS[joint_id].MIN);
        System::outputSerial().println(F(","));

        System::outputSerial().print(F("\t\t\"home\": "));
        System::outputSerial().println(m_SETTINGS[joint_id].HOME);

        System::outputSerial().print(F("\t}"));

        if (joint_id != (JOINTS_SUM - 1))
        {
            System::outputSerial().println(F(","));
        }
        else
        {
            System::outputSerial().println();
        }
    }

    System::outputSerial().println(F("]"));
}
Esempio n. 13
0
void PLEN2::Soul::log()
{
    #if DEBUG
        PROFILING("Soul::log()");
    #endif


    if (   m_motion_ctrl_ptr->playing()
        || (millis() < m_next_sampling_msec) )
    {
        return;
    }

    /*!
        @note
        If something data arrived in the serial buffer already,
        return the method to keep the integrity of the data.
    */
    if (   System::BLESerial().available()
        || System::USBSerial().available() )
    {
        return;
    }


    m_sensor_ptr->sampling();

    Shared::acc_backup[X_AXIS] += m_sensor_ptr->getAccX();
    Shared::acc_backup[Y_AXIS] += m_sensor_ptr->getAccY();
    Shared::acc_backup[Z_AXIS] += m_sensor_ptr->getAccZ();

    m_next_sampling_msec += SAMPLING_INTERVAL_MSEC;
    m_log_count++;

    m_preprocess();
}
/****** qmaster/threads/sge_scheduler_main() **********************************
*  NAME
*     sge_scheduler_main() -- main function of the scheduler thread 
*
*  SYNOPSIS
*     void * sge_scheduler_main(void *arg) 
*
*  FUNCTION
*     Main function of the scheduler thread, 
*
*  INPUTS
*     void *arg - pointer to the thread function (type cl_thread_settings_t*) 
*
*  RESULT
*     void * - always NULL 
*
*  NOTES
*     MT-NOTE: sge_scheduler_main() is MT safe 
*
*     MT-NOTE: this is a thread function. Do NOT use this function
*     MT-NOTE: in any other way!
*
*  SEE ALSO
*     qmaster/threads/sge_scheduler_initialize() 
*     qmaster/threads/sge_scheduler_cleanup_thread() 
*     qmaster/threads/sge_scheduler_terminate() 
*     qmaster/threads/sge_scheduler_main() 
*******************************************************************************/
void *
sge_scheduler_main(void *arg)
{
   time_t next_prof_output = 0;
   monitoring_t monitor;
   sge_gdi_ctx_class_t *ctx = NULL;
   sge_evc_class_t *evc = NULL;
   lList *alp = NULL;
   sge_where_what_t where_what;
   cl_thread_settings_t *thread_config = (cl_thread_settings_t*)arg;
   bool do_shutdown = false;
   bool do_endlessly = true;
   bool local_ret = true;

   DENTER(TOP_LAYER, "sge_scheduler_main");

   memset(&where_what, 0, sizeof(where_what));

   /*
    * startup
    */
   if (local_ret) {
      /* initialize commlib thread */
      cl_thread_func_startup(thread_config);

      /* initialize monitoring */
      sge_monitor_init(&monitor, thread_config->thread_name, SCH_EXT, SCT_WARNING, SCT_ERROR);
      sge_qmaster_thread_init(&ctx, SCHEDD, SCHEDD_THREAD, true);

      /* register at profiling module */
      set_thread_name(pthread_self(), "Scheduler Thread");
      conf_update_thread_profiling("Scheduler Thread");
      DPRINTF((SFN" started\n", thread_config->thread_name));

      /* initialize schedd_runnlog logging */
      schedd_set_schedd_log_file(ctx);
   }

   /* set profiling parameters */
   prof_set_level_name(SGE_PROF_EVENTMASTER, NULL, NULL);
   prof_set_level_name(SGE_PROF_SPOOLING, NULL, NULL);
   prof_set_level_name(SGE_PROF_CUSTOM0, "scheduler", NULL);
   prof_set_level_name(SGE_PROF_CUSTOM1, "pending ticket calculation", NULL);
   prof_set_level_name(SGE_PROF_CUSTOM3, "job sorting", NULL);
   prof_set_level_name(SGE_PROF_CUSTOM4, "job dispatching", NULL);
   prof_set_level_name(SGE_PROF_CUSTOM5, "send orders", NULL);
   prof_set_level_name(SGE_PROF_CUSTOM6, "scheduler event loop", NULL);
   prof_set_level_name(SGE_PROF_CUSTOM7, "copy lists", NULL);
   prof_set_level_name(SGE_PROF_SCHEDLIB4, NULL, NULL);

   /* set-up needed for 'schedule' file */
   serf_init(schedd_serf_record_func, schedd_serf_newline);
   schedd_set_serf_log_file(ctx);

   /*
    * prepare event client/mirror mechanism
    */
   if (local_ret) {
      local_ret = sge_gdi2_evc_setup(&evc, ctx, EV_ID_SCHEDD, &alp, "scheduler");
      DPRINTF(("prepared event client/mirror mechanism\n"));
   }

   /*
    * register as event mirror
    */
   if (local_ret) {
      sge_mirror_initialize(evc, EV_ID_SCHEDD, "scheduler",
                            false, &event_update_func, &sge_mod_event_client,
                            &sge_add_event_client, &sge_remove_event_client,
                            &sge_handle_event_ack);
      evc->ec_register(evc, false, NULL, &monitor);
      evc->ec_set_busy_handling(evc, EV_BUSY_UNTIL_RELEASED);
      DPRINTF(("registered at event mirror\n"));
   }

   /*
    * subscribe necessary data
    */
   if (local_ret) {
      ensure_valid_what_and_where(&where_what);
      subscribe_scheduler(evc, &where_what);
      DPRINTF(("subscribed necessary data from event master\n"));
   }

   /* 
    * schedulers main loop
    */
   if (local_ret) {
      while (do_endlessly) {
         bool handled_events = false;
         lList *event_list = NULL;
         int execute = 0;
         double prof_copy = 0.0;
         double prof_total = 0.0;
         double prof_init = 0.0;
         double prof_free = 0.0;
         double prof_run = 0.0;
         lList *orders = NULL;

         if (sconf_get_profiling()) {
            prof_start(SGE_PROF_OTHER, NULL);
            prof_start(SGE_PROF_PACKING, NULL);
            prof_start(SGE_PROF_EVENTCLIENT, NULL);
            prof_start(SGE_PROF_MIRROR, NULL);
            prof_start(SGE_PROF_GDI, NULL);
            prof_start(SGE_PROF_HT_RESIZE, NULL);
            prof_start(SGE_PROF_CUSTOM0, NULL);
            prof_start(SGE_PROF_CUSTOM1, NULL);
            prof_start(SGE_PROF_CUSTOM3, NULL);
            prof_start(SGE_PROF_CUSTOM4, NULL);
            prof_start(SGE_PROF_CUSTOM5, NULL);
            prof_start(SGE_PROF_CUSTOM6, NULL);
            prof_start(SGE_PROF_CUSTOM7, NULL);
            prof_start(SGE_PROF_SCHEDLIB4, NULL);
         } else {
            prof_stop(SGE_PROF_OTHER, NULL);
            prof_stop(SGE_PROF_PACKING, NULL);
            prof_stop(SGE_PROF_EVENTCLIENT, NULL);
            prof_stop(SGE_PROF_MIRROR, NULL);
            prof_stop(SGE_PROF_GDI, NULL);
            prof_stop(SGE_PROF_HT_RESIZE, NULL);
            prof_stop(SGE_PROF_CUSTOM0, NULL);
            prof_stop(SGE_PROF_CUSTOM1, NULL);
            prof_stop(SGE_PROF_CUSTOM3, NULL);
            prof_stop(SGE_PROF_CUSTOM4, NULL);
            prof_stop(SGE_PROF_CUSTOM5, NULL);
            prof_stop(SGE_PROF_CUSTOM6, NULL);
            prof_stop(SGE_PROF_CUSTOM7, NULL);
            prof_stop(SGE_PROF_SCHEDLIB4, NULL);
         }

         /*
          * Wait for new events
          */
         MONITOR_IDLE_TIME(sge_scheduler_wait_for_event(evc, &event_list), (&monitor), mconf_get_monitor_time(), 
                           mconf_is_monitor_message());

         /* If we lost connection we have to register again */
         if (evc->ec_need_new_registration(evc)) {
            lFreeList(&event_list);
            if (evc->ec_register(evc, false, NULL, &monitor) == true) {
               DPRINTF(("re-registered at event master!\n"));
            }
         }

         if (event_list != NULL) {
            /* check for shutdown */
            do_shutdown = (lGetElemUlong(event_list, ET_type, sgeE_SHUTDOWN) != NULL) ? true : false;

            /* update mirror and free data */
            if (do_shutdown == false && sge_mirror_process_event_list(evc, event_list) == SGE_EM_OK) {
               handled_events = true;
               DPRINTF(("events handled\n"));
            } else {
               DPRINTF(("events contain shutdown event - ignoring events\n"));
            }
            lFreeList(&event_list);
         }
 
         /* if we actually got events, start the scheduling run and further event processing */
         if (handled_events == true) {
            lList *answer_list = NULL;
            scheduler_all_data_t copy;
            lList *master_cqueue_list = *(object_type_get_master_list(SGE_TYPE_CQUEUE));
            lList *master_job_list = *object_type_get_master_list(SGE_TYPE_JOB);
            lList *master_userset_list = *object_type_get_master_list(SGE_TYPE_USERSET);
            lList *master_project_list = *object_type_get_master_list(SGE_TYPE_PROJECT);
            lList *master_exechost_list= *object_type_get_master_list(SGE_TYPE_EXECHOST);
            lList *master_rqs_list= *object_type_get_master_list(SGE_TYPE_RQS);
            lList *master_centry_list = *object_type_get_master_list(SGE_TYPE_CENTRY);
            lList *master_ckpt_list = *object_type_get_master_list(SGE_TYPE_CKPT);
            lList *master_user_list = *object_type_get_master_list(SGE_TYPE_USER);
            lList *master_ar_list = *object_type_get_master_list(SGE_TYPE_AR);
            lList *master_pe_list = *object_type_get_master_list(SGE_TYPE_PE);
            lList *master_hgrp_list = *object_type_get_master_list(SGE_TYPE_HGROUP);
            lList *master_sharetree_list = *object_type_get_master_list(SGE_TYPE_SHARETREE);

            /* delay scheduling for test purposes, see issue GE-3306 */
            if (SGE_TEST_DELAY_SCHEDULING > 0) {
               sleep(SGE_TEST_DELAY_SCHEDULING);
            }

            PROF_START_MEASUREMENT(SGE_PROF_CUSTOM6);
            PROF_START_MEASUREMENT(SGE_PROF_CUSTOM7);

            if (__CONDITION(INFOPRINT)) {
               dstring ds;
               char buffer[128];

               sge_dstring_init(&ds, buffer, sizeof(buffer));
               DPRINTF(("================[SCHEDULING-EPOCH %s]==================\n",
                        sge_at_time(0, &ds)));
               sge_dstring_free(&ds);
            }

            /*
             * If there were new events then
             * copy/filter data necessary for the scheduler run
             * and run the scheduler method
             */
            memset(&copy, 0, sizeof(copy));

            copy.dept_list = lSelect("", master_userset_list, where_what.where_dept, where_what.what_acldept);
            copy.acl_list = lSelect("", master_userset_list, where_what.where_acl, where_what.what_acldept);

            DPRINTF(("RAW CQ:%d, J:%d, H:%d, C:%d, A:%d, D:%d, P:%d, CKPT:%d,"
                     " US:%d, PR:%d, RQS:%d, AR:%d, S:nd:%d/lf:%d\n",
               lGetNumberOfElem(master_cqueue_list),
               lGetNumberOfElem(master_job_list),
               lGetNumberOfElem(master_exechost_list),
               lGetNumberOfElem(master_centry_list),
               lGetNumberOfElem(copy.acl_list),
               lGetNumberOfElem(copy.dept_list),
               lGetNumberOfElem(master_project_list),
               lGetNumberOfElem(master_ckpt_list),
               lGetNumberOfElem(master_user_list),
               lGetNumberOfElem(master_project_list),
               lGetNumberOfElem(master_rqs_list),
               lGetNumberOfElem(master_ar_list),
               lGetNumberOfNodes(NULL, master_sharetree_list, STN_children),
               lGetNumberOfLeafs(NULL, master_sharetree_list, STN_children)
            ));

            sge_rebuild_job_category(master_job_list, master_userset_list,
                                        master_project_list, master_rqs_list);

            PROF_STOP_MEASUREMENT(SGE_PROF_CUSTOM7);
            prof_init = prof_get_measurement_wallclock(SGE_PROF_CUSTOM7, true, NULL);
            PROF_START_MEASUREMENT(SGE_PROF_CUSTOM7);

            sge_before_dispatch(evc);

            /* prepare data for the scheduler itself */
            copy.host_list = lCopyList("", master_exechost_list);

            /*
             * Within the scheduler we do only need QIs
             */
            {
               lListElem *cqueue = NULL;
               lEnumeration *what_queue3 = NULL;

               for_each(cqueue, master_cqueue_list) {
                  lList *qinstance_list = lGetList(cqueue, CQ_qinstances);
                  lList *t;

                  if (!qinstance_list) {
                     continue;
                  }

                  /* all_queue_list contains all queue instances with state and full queue name only */
                  if (!what_queue3) {
                     what_queue3 = lWhat("%T(%I%I)", lGetListDescr(qinstance_list), QU_full_name, QU_state);
                  }
                  t = lSelect("t", qinstance_list, NULL, what_queue3);
                  if (t) {
                     if (copy.all_queue_list == NULL) {
                        copy.all_queue_list = lCreateList("all", lGetListDescr(t));
                     }
                     lAppendList(copy.all_queue_list, t);
                     lFreeList (&t);
                  }

                  t = lSelect("t", qinstance_list, where_what.where_queue, where_what.what_queue2);
                  if (t) {
                     if (copy.queue_list == NULL) {
                        copy.queue_list = lCreateList("enabled", lGetListDescr(t));
                     }
                     lAppendList(copy.queue_list, t);
                     lFreeList (&t);
                  }

                  t = lSelect("t", qinstance_list, where_what.where_queue2, where_what.what_queue2);
                  if (t) {
                     if (copy.dis_queue_list == NULL) {
                        copy.dis_queue_list = lCreateList("disabled", lGetListDescr(t));
                     }
                     lAppendList(copy.dis_queue_list, t);
                     lFreeList (&t);
                  }
               }
               if (what_queue3) {
                  lFreeWhat(&what_queue3);
               }
            }

            if (sconf_is_job_category_filtering()) {
               copy.job_list = sge_category_job_copy(copy.queue_list, &orders, evc->monitor_next_run);
            } else {
               copy.job_list = lCopyList("", master_job_list);
            }

            /* no need to copy these lists, they are read only used */
            copy.centry_list = master_centry_list;
            copy.ckpt_list = master_ckpt_list;
            copy.hgrp_list = master_hgrp_list;

            /* these lists need to be copied because they are modified during scheduling run */
            copy.share_tree = lCopyList("", master_sharetree_list);
            copy.pe_list = lCopyList("", master_pe_list);
            copy.user_list = lCopyList("", master_user_list);
            copy.project_list = lCopyList("", master_project_list);
            copy.rqs_list = lCopyList("", master_rqs_list);
            copy.ar_list = lCopyList("", master_ar_list);

            /* report number of reduced and raw (in brackets) lists */
            DPRINTF(("Q:%d, AQ:%d J:%d(%d), H:%d(%d), C:%d, A:%d, D:%d, P:%d, CKPT:%d,"
                     " US:%d, PR:%d, RQS:%d, AR:%d, S:nd:%d/lf:%d \n",
               lGetNumberOfElem(copy.queue_list),
               lGetNumberOfElem(copy.all_queue_list),
               lGetNumberOfElem(copy.job_list),
               lGetNumberOfElem(master_job_list),
               lGetNumberOfElem(copy.host_list),
               lGetNumberOfElem(master_exechost_list),
               lGetNumberOfElem(copy.centry_list),
               lGetNumberOfElem(copy.acl_list),
               lGetNumberOfElem(copy.dept_list),
               lGetNumberOfElem(copy.pe_list),
               lGetNumberOfElem(copy.ckpt_list),
               lGetNumberOfElem(copy.user_list),
               lGetNumberOfElem(copy.project_list),
               lGetNumberOfElem(copy.rqs_list),
               lGetNumberOfElem(copy.ar_list),
               lGetNumberOfNodes(NULL, copy.share_tree, STN_children),
               lGetNumberOfLeafs(NULL, copy.share_tree, STN_children)
            ));

            if (getenv("SGE_ND")) {
               printf("Q:%d, AQ:%d J:%d(%d), H:%d(%d), C:%d, A:%d, D:%d, "
                  "P:%d, CKPT:%d, US:%d, PR:%d, RQS:%d, AR:%d, S:nd:%d/lf:%d \n",
                  lGetNumberOfElem(copy.queue_list),
                  lGetNumberOfElem(copy.all_queue_list),
                  lGetNumberOfElem(copy.job_list),
                  lGetNumberOfElem(master_job_list),
                  lGetNumberOfElem(copy.host_list),
                  lGetNumberOfElem(master_exechost_list),
                  lGetNumberOfElem(copy.centry_list),
                  lGetNumberOfElem(copy.acl_list),
                  lGetNumberOfElem(copy.dept_list),
                  lGetNumberOfElem(copy.pe_list),
                  lGetNumberOfElem(copy.ckpt_list),
                  lGetNumberOfElem(copy.user_list),
                  lGetNumberOfElem(copy.project_list),
                  lGetNumberOfElem(copy.rqs_list),
                  lGetNumberOfElem(copy.ar_list),
                  lGetNumberOfNodes(NULL, copy.share_tree, STN_children),
                  lGetNumberOfLeafs(NULL, copy.share_tree, STN_children)
                 );
            } else {
               schedd_log("-------------START-SCHEDULER-RUN-------------", NULL, evc->monitor_next_run);
            }

            PROF_STOP_MEASUREMENT(SGE_PROF_CUSTOM7);
            prof_copy = prof_get_measurement_wallclock(SGE_PROF_CUSTOM7, true, NULL);
            PROF_START_MEASUREMENT(SGE_PROF_CUSTOM7);

            scheduler_method(evc, &answer_list, &copy, &orders);
            answer_list_output(&answer_list);

            PROF_STOP_MEASUREMENT(SGE_PROF_CUSTOM7);
            prof_run = prof_get_measurement_wallclock(SGE_PROF_CUSTOM7, true, NULL);
            PROF_START_MEASUREMENT(SGE_PROF_CUSTOM7);

            /* .. which gets deleted after using */
            lFreeList(&(copy.host_list));
            lFreeList(&(copy.queue_list));
            lFreeList(&(copy.dis_queue_list));
            lFreeList(&(copy.all_queue_list));
            lFreeList(&(copy.job_list));
            lFreeList(&(copy.acl_list));
            lFreeList(&(copy.dept_list));
            lFreeList(&(copy.pe_list));
            lFreeList(&(copy.share_tree));
            lFreeList(&(copy.user_list));
            lFreeList(&(copy.project_list));
            lFreeList(&(copy.rqs_list));
            lFreeList(&(copy.ar_list));

            PROF_STOP_MEASUREMENT(SGE_PROF_CUSTOM7);
            prof_free = prof_get_measurement_wallclock(SGE_PROF_CUSTOM7, true, NULL);

            /* 
             * need to sync with event master thread
             * if schedd configuration changed then settings in evm can be adjusted
             */
            if (sconf_is_new_config()) {
               /* set scheduler interval / event delivery interval */
               u_long32 interval = sconf_get_schedule_interval();
               if (evc->ec_get_edtime(evc) != interval) {
                  evc->ec_set_edtime(evc, interval);
               }

               /* set job / ja_task event flushing */
               set_job_flushing(evc);

               /* no need to ec_commit here - we do it when resetting the busy state */

               /* now we handled the new schedd config - no need to do it twice */
               sconf_reset_new_config();
            }

            /* block till master handled all GDI orders */
            sge_schedd_block_until_orders_processed(evc->get_gdi_ctx(evc), NULL);
            schedd_order_destroy();

            /*
             * Stop profiling for "schedd run total" and the subcategories
             */
            PROF_STOP_MEASUREMENT(SGE_PROF_CUSTOM6);
            prof_total = prof_get_measurement_wallclock(SGE_PROF_CUSTOM6, true, NULL);

            if (prof_is_active(SGE_PROF_CUSTOM6)) {
               PROFILING((SGE_EVENT, "PROF: schedd run took: %.3f s (init: %.3f s, copy: %.3f s, "
                          "run:%.3f, free: %.3f s, jobs: %d, categories: %d/%d)",
                           prof_total, prof_init, prof_copy, prof_run, prof_free,
                           lGetNumberOfElem(*object_type_get_master_list(SGE_TYPE_JOB)), sge_category_count(),
                           sge_cs_category_count() ));
            }
            if (getenv("SGE_ND") != NULL) {
               printf("--------------STOP-SCHEDULER-RUN-------------\n");
            } else {
               schedd_log("--------------STOP-SCHEDULER-RUN-------------", NULL, evc->monitor_next_run);
            }

            thread_output_profiling("scheduler thread profiling summary:\n", &next_prof_output);

            sge_monitor_output(&monitor);
         }

         /* reset the busy state */
         evc->ec_set_busy(evc, 0);
         evc->ec_commit(evc, NULL);

         /* stop logging into schedd_runlog (enabled via -tsm) */
         evc->monitor_next_run = false;

         /*
          * pthread cancelation point
          *
          * sge_scheduler_cleanup_thread() is the last function which should
          * be called so it is pushed first
          */
         pthread_cleanup_push(sge_scheduler_cleanup_thread, (void *) &ctx);
         pthread_cleanup_push((void (*)(void *))sge_scheduler_cleanup_monitor,
                              (void *)&monitor);
         pthread_cleanup_push((void (*)(void *))sge_scheduler_cleanup_event_client,
                              (void *)evc);
         cl_thread_func_testcancel(thread_config);
         pthread_cleanup_pop(execute);
         pthread_cleanup_pop(execute);
         pthread_cleanup_pop(execute);
         DPRINTF(("passed cancelation point\n"));
      }