Exemplo n.º 1
0
int
main(int argc, char **argv)
{
    ConnCacheEntry cce;
    struct rx_connection conn;
    struct rx_peer peer;
    unsigned long number;
    void *pe, *pe2;
    PROCESS p;

    LWP_InitializeProcessSupport(4, &p);
    arla_loginit("/dev/stdout", 0);
    cell_init(0, arla_log_method);
    poller_init();

    memset(&cce, 0, sizeof(cce));
    memset(&conn, 0, sizeof(conn));
    memset(&peer, 0, sizeof(peer));
    
    conn.peer = &peer;
    cce.connection = &conn;

    printf("add\n");
    number = 1000000;
    while(number--) {
	pe = poller_add_conn(&cce);
    }
    poller_remove(pe);

    printf("add-remove\n");
    number = 1000000;
    while(number--) {
	pe = poller_add_conn(&cce);
	poller_remove(pe);
    }

    printf("add-add-remove-remove-remove\n");
    pe = NULL;
    number = 1000000;
    while(number--) {
	pe = poller_add_conn(&cce);
	pe2 = poller_add_conn(&cce);
	if (pe != pe2)
		exit(-1);
	poller_remove(pe);
	poller_remove(pe2);
    }
    return 0;
}
Exemplo n.º 2
0
/* FIXME: it will be a platform device */
static int psh_probe(struct spi_device *client)
{
	int ret = -EPERM;
	struct psh_ia_priv *ia_data;
	struct psh_ext_if *psh_if_info;
	int rc;
	
	dev_err(&client->dev, "%s\n", __func__);

	psh_if_info = kzalloc(sizeof(*psh_if_info), GFP_KERNEL);
	if (!psh_if_info) {
		dev_err(&client->dev, "can not allocate psh_if_info\n");
		goto psh_if_err;
	}

	ret = psh_ia_common_init(&client->dev, &psh_if_info->ia_data);
	if (ret) {
		dev_err(&client->dev, "fail to init psh_ia_common\n");
		goto psh_ia_err;
	}

    ia_data = psh_if_info->ia_data;

    /*
      initialize send list
     */
    mutex_init(&psh_if_info->send_data_list.lock);
    mutex_init(&psh_if_info->workitem_mutex);
    INIT_LIST_HEAD(&psh_if_info->send_data_list.head);
    
    psh_if_info->task_flag = TASK_FLAG_CLEAR;
    dev_err(&client->dev, "send list inited\n");

	psh_if_info->hwmon_dev = hwmon_device_register(&client->dev);
	if (!psh_if_info->hwmon_dev) {
		dev_err(&client->dev, "fail to register hwmon device\n");
		goto hwmon_err;
	}

	psh_if_info->pshc = client;

	ia_data->platform_priv = psh_if_info;

#if 0
	psh_if_info->gpio_psh_ctl =
				acpi_get_gpio_by_index(&client->dev, 1, NULL);
#endif

	psh_if_info->gpio_psh_ctl = -1;

	if (psh_if_info->gpio_psh_ctl < 0) {
		dev_warn(&client->dev, "fail to get psh_ctl pin by ACPI\n");
	} else {
		rc = gpio_request(psh_if_info->gpio_psh_ctl, "psh_ctl");
		if (rc) {
			dev_warn(&client->dev, "fail to request psh_ctl pin\n");
			psh_if_info->gpio_psh_ctl = -1;
		} else {
			gpio_export(psh_if_info->gpio_psh_ctl, 1);
			gpio_direction_output(psh_if_info->gpio_psh_ctl, 1);
			gpio_set_value(psh_if_info->gpio_psh_ctl, 1);
		}
	}
#if 0
	psh_if_info->gpio_psh_rst =
				acpi_get_gpio_by_index(&client->dev, 0, NULL);
#endif 

	psh_if_info->gpio_psh_rst = GPIO_PSH_MCU_RESET;

	if (psh_if_info->gpio_psh_rst < 0) {
		dev_warn(&client->dev, "failed to get psh_rst pin by ACPI\n");
	} else {
		rc = gpio_request(psh_if_info->gpio_psh_rst, "psh_rst");
		if (rc) {
			dev_warn(&client->dev, "fail to request psh_rst pin\n");
			psh_if_info->gpio_psh_rst = -1;
		} else {
			gpio_export(psh_if_info->gpio_psh_rst, 1);
			gpio_direction_output(psh_if_info->gpio_psh_rst, 1);
			gpio_set_value(psh_if_info->gpio_psh_rst, 1);
		}
	}
	// TODO update gpio_psh_int from platform_data 
	//psh_if_info->gpio_psh_int = (int)id->driver_data;
	
	client->irq = gpio_to_irq(GPIO_PSH_INT);  // force polling mode
#ifdef DRV_POLLING_MODE
	client->irq = -1;
#endif
 
	if(client->irq > 0){

	    psh_if_info->gpio_psh_int = GPIO_PSH_INT; 
	
	    rc = gpio_request(psh_if_info->gpio_psh_int, "psh_int");
	    if (rc) {
		    dev_warn(&client->dev, "fail to request psh_int pin\n");
		    psh_if_info->gpio_psh_int = -1;
	    } else {
		    gpio_export(psh_if_info->gpio_psh_int, 1);
	    }

	    /* set the flag to to enable irq when need */
	    irq_set_status_flags(client->irq, IRQ_NOAUTOEN);

	    ret = request_threaded_irq(client->irq, NULL, psh_byt_irq_thread,
			IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "psh_byt", client);
	    if (ret) {
		    dev_err(&client->dev, "fail to request irq\n");
		    goto irq_err;
	    }

	    psh_if_info->irq_disabled = 1;
    }

#ifdef DRV_POLLING_MODE 
	psh_if_info->gpio_psh_int = GPIO_PSH_INT;
	rc = gpio_request(psh_if_info->gpio_psh_int, "psh_int");
	if (rc) {
		    dev_warn(&client->dev, "fail to request psh_int pin\n");
		    psh_if_info->gpio_psh_int = -1;
	}
	else {
		    gpio_export(psh_if_info->gpio_psh_int, 1);
			gpio_direction_input(psh_if_info->gpio_psh_int);
	}
#endif 	

    //    psh_if_info->wq = create_singlethread_workqueue("psh_work");
    /*    psh_if_info->wq = alloc_ordered_workqueue("%S", WQ_MEM_RECLAIM|WQ_HIGHPRI, "psh_work");*/


    psh_if_info->wq = alloc_workqueue("%s", WQ_HIGHPRI, 0, "psh_work");

#if 1

    //just a profiler here
    timestamp_init_with_name(&client->dev, 
                             &psh_if_info->io_profiler, "profile_pull");

    poller_init(&psh_if_info->poller_worker,
                poll_sensor_data_by_thread, psh_if_info);

    poller_set_frequency(&psh_if_info->poller_worker, 1000);

    if (!IS_SUCCESS(poller_start(&client->dev,
                                 &psh_if_info->poller_worker)))
    {
        dev_err(&client->dev, "fail to create poller\n");
        goto wq_err;
    }

    /*
      try sync timestamp with sensorhub fw once 
     */
    ia_sync_timestamp_with_sensorhub_fw(psh_if_info->ia_data);

#endif

	if (!psh_if_info->wq) {
	    dev_err(&client->dev, "fail to create workqueue\n");
		goto wq_err;
	}
    
	INIT_WORK(&psh_if_info->work, psh_work_func);
    
    
    //dev_err(&client->dev, "sensor polling speed: %dHZ\n", POLL_HZ_PER_SECOND);
    
#ifdef DRV_POLLING_MODE 	
	INIT_DELAYED_WORK(&psh_if_info->dwork, poll_sensor_data);
#endif 

#ifdef ENABLE_RPM	
	pm_runtime_set_active(&client->dev);
	pm_runtime_use_autosuspend(&client->dev);
	pm_runtime_set_autosuspend_delay(&client->dev, 0);
	pm_runtime_enable(&client->dev);
#endif 

#ifndef DRV_POLLING_MODE 
	psh_if_info->irq_disabled = 0;
    enable_irq(psh_if_info->pshc->irq);
#endif 

	return 0;

wq_err:
	free_irq(client->irq, psh_if_info->pshc);
irq_err:
	hwmon_device_unregister(psh_if_info->hwmon_dev);
hwmon_err:
	psh_ia_common_deinit(&client->dev);
psh_ia_err:
	kfree(psh_if_info);
psh_if_err:
	return ret;
}