void loadavg_init() { color_t c = { 0, COLOR_MAX/2, COLOR_MAX/2 }; base_set(c, LED_LOAD_1); load_update(&Load_update, 0); load_blink(&Load_blink, 0); }
/* * The boot processos timer interrupt handler. In addition to non-boot cpus it * keeps real time and notifies the clock task if need be */ int timer_int_handler(void) { /* Update user and system accounting times. Charge the current process * for user time. If the current process is not billable, that is, if a * non-user process is running, charge the billable process for system * time as well. Thus the unbillable process' user time is the billable * user's system time. */ struct proc * p, * billp; /* FIXME watchdog for slave cpus! */ #ifdef USE_WATCHDOG /* * we need to know whether local timer ticks are happening or whether * the kernel is locked up. We don't care about overflows as we only * need to know that it's still ticking or not */ watchdog_local_timer_ticks++; #endif if (cpu_is_bsp(cpuid)) realtime++; /* Update user and system accounting times. Charge the current process * for user time. If the current process is not billable, that is, if a * non-user process is running, charge the billable process for system * time as well. Thus the unbillable process' user time is the billable * user's system time. */ p = get_cpulocal_var(proc_ptr); billp = get_cpulocal_var(bill_ptr); p->p_user_time++; if (! (priv(p)->s_flags & BILLABLE)) { billp->p_sys_time++; } /* Decrement virtual timers, if applicable. We decrement both the * virtual and the profile timer of the current process, and if the * current process is not billable, the timer of the billed process as * well. If any of the timers expire, do_clocktick() will send out * signals. */ if ((p->p_misc_flags & MF_VIRT_TIMER)){ p->p_virt_left--; } if ((p->p_misc_flags & MF_PROF_TIMER)){ p->p_prof_left--; } if (! (priv(p)->s_flags & BILLABLE) && (billp->p_misc_flags & MF_PROF_TIMER)){ billp->p_prof_left--; } /* * Check if a process-virtual timer expired. Check current process, but * also bill_ptr - one process's user time is another's system time, and * the profile timer decreases for both! */ vtimer_check(p); if (p != billp) vtimer_check(billp); /* Update load average. */ load_update(); if (cpu_is_bsp(cpuid)) { /* if a timer expired, notify the clock task */ if ((next_timeout <= realtime)) { tmrs_exptimers(&clock_timers, realtime, NULL); next_timeout = (clock_timers == NULL) ? TMR_NEVER : clock_timers->tmr_exp_time; } #ifdef DEBUG_SERIAL if (do_serial_debug) do_ser_debug(); #endif } return(1); /* reenable interrupts */ }
bool CConfigLoader::load(const std::string& filepath) { Json::Reader reader; Json::Value root; std::ifstream fs(filepath.c_str()); struct DbInfo* db_info_array[MAX_DB_CONNECTION] = { NULL }; struct QueryInfo* query_info_array[MAX_SQL_TEMPLATE] = { NULL }; struct UpdateInfo* update_info_array[MAX_SQL_TEMPLATE] = { NULL }; if (_md5_sum.empty()) { MYLOG_INFO("loading %s\n", filepath.c_str()); } else { MYLOG_DETAIL("loading %s\n", filepath.c_str()); } if (!fs) { MYLOG_ERROR("load %s failed: %s\n", filepath.c_str(), strerror(errno)); return false; } if (!reader.parse(fs, root)) { MYLOG_ERROR("parse %s failed: %s\n", filepath.c_str(), reader.getFormattedErrorMessages().c_str()); return false; } // 检查文件是否有修改过 std::string md5_sum = utils::CMd5Helper::lowercase_md5("%s", root.toStyledString().c_str()); if (md5_sum == _md5_sum) { MYLOG_DETAIL("not changed: (%s)%s\n", md5_sum.c_str(), filepath.c_str()); return true; // 未发生变化 } init_db_info_array(db_info_array); init_query_info_array(query_info_array); init_update_info_array(update_info_array); if (!load_database(root["database"], db_info_array)) return false; if (!load_query(root["query"], query_info_array)) return false; if (!load_update(root["update"], update_info_array)) return false; int i; // 加写锁 sys::WriteLockHelper write_lock(_read_write_lock); release_db_info_array(_db_info_array); release_query_info_array(_query_info_array); release_update_info_array(_update_info_array); for (i=0; i<MAX_DB_CONNECTION; ++i) { if (db_info_array[i] != NULL) { // 启动时即连接一下,以早期发现配置等问题 _db_info_array[i] = new struct DbInfo(*db_info_array[i]); sys::DBConnection* db_connection = init_db_connection(i, false); if (db_connection != NULL) { delete db_connection; db_connection = NULL; } } } for (i=0; i<MAX_SQL_TEMPLATE; ++i) { if (query_info_array[i] != NULL) _query_info_array[i] = new struct QueryInfo(*query_info_array[i]); if (update_info_array[i] != NULL) _update_info_array[i] = new struct UpdateInfo(*update_info_array[i]); } _md5_sum = md5_sum; MYLOG_INFO("loaded %s[%s] successfully\n", filepath.c_str(), _md5_sum.c_str()); return true; }