Ejemplo n.º 1
0
static eEsifError EsifDataLogValidateParticipantList(char *inParticipantList)
{
	int i = 0;
	char *participantList = NULL;
	char *participantSelect = NULL;
	char colDelims [] = ",";
	char *partTok = NULL;
	UInt8 participantId = 0;
	int participantCounter = 0;
	int totalFields = 0;
	eEsifError rc = ESIF_OK;

	for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++){
		g_dataLogParticipants[i].participantId = 0;
		g_dataLogParticipants[i].participantNumFields = 0;
	}
	
	if (inParticipantList == NULL) {
		for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
			EsifUpPtr upPtr = NULL;

			participantId = (UInt8) i;
			upPtr = EsifUpPm_GetAvailableParticipantByInstance(participantId);

			if (NULL != upPtr) {
				int j = 0;
				int fieldCounter = 0;
				struct esif_fpc_domain *domainPtr = NULL;
				UInt8 domainCount = (u8)upPtr->fDspPtr->get_domain_count(upPtr->fDspPtr);
				DataLogParticipant nextParticipant = { 0 };

				for (j = 0; j < domainCount; j++) {
					domainPtr = upPtr->fDspPtr->get_domain(upPtr->fDspPtr, j + 1);
					if (NULL == domainPtr) {
						continue;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_TEMP_STATUS) {
						fieldCounter += 4;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_POWER_CONTROL) {
						fieldCounter += 2;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_ACTIVE_CONTROL) {
						fieldCounter += 1;
					}
				}
				nextParticipant.participantId = participantId;
				nextParticipant.participantNumFields = fieldCounter;
				g_dataLogParticipants[participantCounter] = nextParticipant;

				totalFields += fieldCounter;
				EsifUp_PutRef(upPtr);
				participantCounter++;
			}
		}
		goto exit;
	}

	if (esif_ccb_strlen(inParticipantList, MAX_LOG_LINE) >= 1) {

		participantList = esif_ccb_strdup(inParticipantList);
		participantSelect = esif_ccb_strtok(participantList, colDelims, &partTok);

		while (participantSelect != NULL) {
			EsifUpPtr upPtr = { 0 };

			if (participantCounter >= (sizeof(g_dataLogParticipants)/sizeof(*g_dataLogParticipants))) {
					rc = ESIF_E_NOT_SUPPORTED;
					goto exit;
			}

			if ((int)esif_atoi(participantSelect) > 0 || esif_ccb_strcmp(participantSelect, "0") == 0) {
				participantId = (UInt8) esif_atoi(participantSelect);
				upPtr = EsifUpPm_GetAvailableParticipantByInstance(participantId);
			}
			else {
				upPtr = EsifUpPm_GetAvailableParticipantByName(participantSelect);
			}
			if (NULL == upPtr) {
				rc = ESIF_E_PARTICIPANT_NOT_FOUND;
				goto exit;
			}
			else {
				int j = 0;
				int fieldCounter = 0;
				struct esif_fpc_domain *domainPtr = NULL;
				UInt8 domainCount = (u8) upPtr->fDspPtr->get_domain_count(upPtr->fDspPtr);
				DataLogParticipant nextParticipant = { 0 };
				participantId = (UInt8) upPtr->fInstance; /* redundant in the case of an id passed in, but needed for name*/

				for (j = 0; j < domainCount; j++) {
					domainPtr = upPtr->fDspPtr->get_domain(upPtr->fDspPtr, j + 1);
					if (NULL == domainPtr) {
						continue;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_TEMP_STATUS) {
						fieldCounter += 4;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_POWER_CONTROL) {
						fieldCounter += 2;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_ACTIVE_CONTROL) {
						fieldCounter += 1;
					}
				}
				nextParticipant.participantId = participantId;
				nextParticipant.participantNumFields = fieldCounter;
				g_dataLogParticipants[participantCounter] = nextParticipant;

				totalFields += fieldCounter;
				EsifUp_PutRef(upPtr);
				participantCounter++;
			}
			participantSelect = esif_ccb_strtok(NULL, colDelims, &partTok);
		}
	}
	else {
		for (i = 0; i < MAX_PARTICIPANT_ENTRY; i++) {
			EsifUpPtr upPtr = NULL;

			participantId = (UInt8) i;
			upPtr = EsifUpPm_GetAvailableParticipantByInstance(participantId);

			if (NULL != upPtr) {
				int j = 0;
				int fieldCounter = 0;
				struct esif_fpc_domain *domainPtr = NULL;
				UInt8 domainCount = (u8)upPtr->fDspPtr->get_domain_count(upPtr->fDspPtr);
				DataLogParticipant nextParticipant = { 0 };

				for (j = 0; j < domainCount; j++) {
					domainPtr = upPtr->fDspPtr->get_domain(upPtr->fDspPtr, j + 1);
					if (NULL == domainPtr) {
						continue;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_TEMP_STATUS) {
						fieldCounter += 4;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_POWER_CONTROL) {
						fieldCounter += 2;
					}
					if (domainPtr->capability_for_domain.capability_flags & ESIF_CAPABILITY_ACTIVE_CONTROL) {
						fieldCounter += 1;
					}
				}
				nextParticipant.participantId = participantId;
				nextParticipant.participantNumFields = fieldCounter;
				g_dataLogParticipants[participantCounter] = nextParticipant;

				totalFields += fieldCounter;
				EsifUp_PutRef(upPtr);
				participantCounter++;
			}
		}
	}
exit:
	esif_ccb_free(participantList);

	if (totalFields == 0) {
		rc = ESIF_E_NOT_SUPPORTED;
	}
	return rc;
}
Ejemplo n.º 2
0
//
// PUBLIC INTERFACE---------------------------------------------------------------------
//
char *EsifShellCmdDataLog(EsifShellCmdPtr shell)
{
	eEsifError rc = ESIF_OK;
	int argc = shell->argc;
	char **argv = shell->argv;
	char *output = shell->outbuf;
	char participantList[MAX_LOG_LINE] = { 0 };

	/*
	 * Serialize access to the datalog state.
	 */
	while (atomic_set(&g_dataLogLock, ESIF_TRUE)) {
		esif_ccb_sleep_msec(ESIF_DATALOG_LOCK_SLEEP_MS);
	}

	if (argc < 2) {
		esif_ccb_sprintf(OUT_BUF_LEN, output, "Data logging is: %s\n", (EsifDataIsLogStarted() ? "started" : "stopped"));
	}
	else if (esif_ccb_stricmp(argv[1], "start") == 0) {

		if (EsifDataIsLogStarted()){
			esif_ccb_sprintf(OUT_BUF_LEN, output, "Data logging is already started.\n");
			goto exit;
		}

		g_dataLogInterval = DEFAULT_STATUS_LOG_INTERVAL;
		if (argc > 2) {
			if ((int)esif_atoi(argv[2]) >= MIN_STATUS_LOG_INTERVAL) {
				g_dataLogInterval = (esif_ccb_time_t)esif_atoi(argv[2]);
			}
			else {
				esif_ccb_sprintf(OUT_BUF_LEN, output, "Invalid sampling period specified (minimum is %d ms).\n", MIN_STATUS_LOG_INTERVAL);
				goto exit;
			}
		}
		if (argc > 3) {
			esif_ccb_sprintf(sizeof(participantList), participantList, "%s", argv[3]);
		}

		rc = EsifDataLogValidateParticipantList(participantList);
		if (rc != ESIF_OK) {
			esif_ccb_sprintf(OUT_BUF_LEN, output, "There was a problem with your participant list. You may have selected invalid participants, or too many participants. \n");
			goto exit;
		}
		rc = EsifDataLogOpenLogFile();
		if (rc != ESIF_OK) {
			esif_ccb_sprintf(OUT_BUF_LEN, output, "Error opening log file... \n");
			goto exit;
		}
		esif_ccb_sprintf(OUT_BUF_LEN, output, "Data logging starting... \n");

		EsifDataLogStart();
	}
	else if (esif_ccb_stricmp(argv[1], "schedule") == 0) {
		UInt32 startTime = 1000;

		/* initialize */
		if (dataLogContextPtr == NULL) {
			dataLogContextPtr = (struct dataLogContext *)esif_ccb_malloc(sizeof(struct dataLogContext));
			if (dataLogContextPtr == NULL) {
				rc = ESIF_E_NO_MEMORY;
				goto exit;
			}
			dataLogContextPtr->dataLogScheduleTimer = (esif_ccb_timer_t *) esif_ccb_malloc(sizeof(esif_ccb_timer_t));
			if (dataLogContextPtr->dataLogScheduleTimer == NULL) {
				rc = ESIF_E_NO_MEMORY;
				goto exit;
			}
			dataLogContextPtr->dataLogParticipantList = NULL;
		}

		dataLogContextPtr->dataLogInterval = DEFAULT_STATUS_LOG_INTERVAL;
		/* start time (in ms from now) */
		if (argc > 2) {
			if ((int) esif_atoi(argv[2]) >= MIN_STATUS_LOG_SCHEDULE) {
				startTime = (esif_ccb_time_t) esif_atoi(argv[2]);
			}
			else {
				esif_ccb_sprintf(OUT_BUF_LEN, output, "Invalid schedule time specified (minimum is %d ms).\n", MIN_STATUS_LOG_INTERVAL);
				goto exit;
			}
		}
		/* log interval */
		if (argc > 3) {
			if ((int) esif_atoi(argv[3]) >= MIN_STATUS_LOG_INTERVAL) {
				dataLogContextPtr->dataLogInterval = (esif_ccb_time_t) esif_atoi(argv[3]);
			}
			else {
				esif_ccb_sprintf(OUT_BUF_LEN, output, "Invalid sampling period specified (minimum is %d ms).\n", MIN_STATUS_LOG_INTERVAL);
				goto exit;
			}
		}
		if (argc > 4) {
			dataLogContextPtr->dataLogParticipantList = esif_ccb_strdup(argv[4]);
			if (dataLogContextPtr->dataLogParticipantList == NULL) {
				rc = ESIF_E_NO_MEMORY;
				goto exit;
			}
		}

		rc = esif_ccb_timer_init(dataLogContextPtr->dataLogScheduleTimer, (esif_ccb_timer_cb) EsifDataLogSchedule, NULL);
		if (ESIF_OK != rc) {
			esif_ccb_sprintf(OUT_BUF_LEN, output, "Error starting timer... \n");
			goto exit;
		}
		rc = esif_ccb_timer_set_msec(dataLogContextPtr->dataLogScheduleTimer, startTime);
		esif_ccb_sprintf(OUT_BUF_LEN, output, "Data logging scheduled for start in %d ms at an interval of %d... \n", startTime, dataLogContextPtr->dataLogInterval);
		
	}
	else if (esif_ccb_stricmp(argv[1], "stop") == 0) {
		EsifDataLogStop();
		esif_ccb_sprintf(OUT_BUF_LEN, output, "Data logging stopped...\n");
		g_dataLogActive = ESIF_FALSE;
	}
	else {
		esif_ccb_sprintf(OUT_BUF_LEN, output, "Invalid parameter specified\n");
	}
exit:
	atomic_set(&g_dataLogLock, ESIF_FALSE);
	return output;
}
Ejemplo n.º 3
0
Archivo: main.c Proyecto: qbbian/dptf
int main (int argc, char **argv)
{
	int c = 0;
	FILE *fp = stdin;
	char command[MAX_LINE + 1] = {0};
	int quit_after_command = ESIF_FALSE;
#if defined(ESIF_ATTR_DAEMON)
        int start_as_server = ESIF_FALSE;
        int start_with_pipe = ESIF_FALSE;
        int start_with_log = ESIF_FALSE;
#else
        int start_as_server = ESIF_TRUE;
#endif

	// Init ESIF
	int rc = chdir("..");

	optind = 1;	// Rest To 1 Restart Vector Scan

	while ((c = getopt(argc, argv, "d:f:c:b:nxhq?spl")) != -1) {
		switch (c) {
		case 'd':
			g_dst = (u8)esif_atoi(optarg);
			break;

		case 'n':
			g_autocpc = ESIF_FALSE;
			break;

		case 'x':
			g_format = FORMAT_XML;
			break;

		case 'b':
			g_binary_buf_size = (int)esif_atoi(optarg);
			break;

		case 'f':
			fp = fopen(optarg, "r");
			break;

		case 'c':
			sprintf(command, "%s", optarg);
			break;

		case 'q':
			quit_after_command = ESIF_TRUE;
			break;

#if defined (ESIF_ATTR_DAEMON)

		case 's':
			start_as_server = ESIF_TRUE;
			break;

		case 'p':
			start_with_pipe = ESIF_TRUE;
			break;

		case 'l':
			start_with_log = ESIF_TRUE;
			break;
#endif

		case 'h':
		case '?':
			printf(
			"EsiF Eco-System Independent Framework Shell\n"
			"(c) 2013 Intel Corp\n\n"
			"-d [*id]            Set Destination\n"
			"-f [*filename]      Load Filename\n"
			"-n                  No Auto CPC Assignment\n"
			"-x                  XML Output Data Format\n"
			"-c [*command]       Issue Shell Command\n"
			"-q                  Quit After Command\n"
			"-b [*size]          Set Binary Buffer Size\n"
#if defined (ESIF_ATTR_DAEMON)
			"-s                  Run As Server\n"
			"-p                  Use Pipe For Input\n"
			"-l                  Use Log For Output\n"
#endif
			"-h or -?            This Help\n\n");
			exit(0);
			break;

		default:
			break;
		}
	}

#if defined (ESIF_ATTR_DAEMON)
        if (start_as_server) {
		run_as_server(fp, command, quit_after_command);
	} else {
		run_as_daemon(start_with_pipe, start_with_log);
	}
#else
	run_as_server(fp, command, quit_after_command);
#endif

 	if (fp && fp != stdin) {
                fclose(fp);
        }

	/* NICE Wait For Worker Thread To Exit */
	printf("Waiting For EVENT Thread To Exit...\n");
	while (!g_quit2) {
		esif_ccb_sleep(1);
	}
	printf("Errorlevel Returned: %d\n", g_errorlevel);

	/* Exit ESIF */
	esif_uf_exit();
	exit(g_errorlevel);
}