static int __init msm_sleep_info_init(void) { int err = 0, cpu = 0; struct sleep_data *sleep_info = NULL; struct hrtimer *timer; //printk(KERN_INFO "msm_sleep_stats: Initializing sleep stats "); sleep_info = &core_sleep_info; adaptive_wq = create_singlethread_workqueue("adaptive"); INIT_WORK(&sleep_info->work, notify_uspace_work_fn); sleep_info->notifier.notifier_call = msm_idle_stats_notified; for_each_possible_cpu(cpu) { timer = &per_cpu(core_sleep_timer, cpu); hrtimer_init(timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); timer->function = timer_func; err = msm_cpuidle_register_notifier(cpu, &sleep_info->notifier); if (err) { /*pr_err("%s: failed to register idle notification\n", __func__)*/; } } err = add_sysfs_objects(sleep_info); if (err) { //printk(KERN_INFO "msm_sleep_stats: Failed to initialize sleep stats"); remove_sysfs_objects(sleep_info); } return 0; }
static int msm_idle_stats_open(struct inode *inode, struct file *filp) { struct msm_idle_stats_device *stats_dev; int rc; if (msm_idle_stats_debug_mask & MSM_IDLE_STATS_DEBUG_API) pr_info("%s: enter\n", __func__); rc = nonseekable_open(inode, filp); if (rc) { pr_err("%s: failed to set nonseekable\n", __func__); goto open_bail; } stats_dev = (struct msm_idle_stats_device *) kzalloc(sizeof(*stats_dev), GFP_KERNEL); if (!stats_dev) { pr_err("%s: failed to allocate device struct\n", __func__); rc = -ENOMEM; goto open_bail; } stats_dev->cpu = MINOR(inode->i_rdev); mutex_init(&stats_dev->mutex); stats_dev->notifier.notifier_call = msm_idle_stats_notified; hrtimer_init(&stats_dev->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED); stats_dev->timer.function = msm_idle_stats_timer; init_waitqueue_head(&stats_dev->wait_q); atomic_set(&stats_dev->collecting, 0); filp->private_data = stats_dev; spin_lock(&msm_idle_stats_devs_lock); if (per_cpu(msm_idle_stats_devs, stats_dev->cpu)) { spin_unlock(&msm_idle_stats_devs_lock); rc = -EBUSY; goto open_free_bail; } per_cpu(msm_idle_stats_devs, stats_dev->cpu) = stats_dev; spin_unlock(&msm_idle_stats_devs_lock); rc = msm_cpuidle_register_notifier(stats_dev->cpu, &stats_dev->notifier); if (rc) { pr_err("%s: failed to register idle notification\n", __func__); goto open_null_bail; } if (msm_idle_stats_debug_mask & MSM_IDLE_STATS_DEBUG_API) pr_info("%s: done\n", __func__); return 0; open_null_bail: spin_lock(&msm_idle_stats_devs_lock); per_cpu(msm_idle_stats_devs, stats_dev->cpu) = NULL; spin_unlock(&msm_idle_stats_devs_lock); open_free_bail: kfree(stats_dev); open_bail: if (msm_idle_stats_debug_mask & MSM_IDLE_STATS_DEBUG_API) pr_info("%s: exit, %d\n", __func__, rc); return rc; }