Ejemplo n.º 1
0
static int migrate_to_node(pid_t pid, int node)
{
	unsigned long nodemask_size, max_node;
	unsigned long *old_nodes, *new_nodes;
	int i;

	tst_resm(TINFO, "pid(%d) migrate pid %d to node -> %d",
		 getpid(), pid, node);
	max_node = LTP_ALIGN(get_max_node(), sizeof(unsigned long)*8);
	nodemask_size = max_node / 8;
	old_nodes = SAFE_MALLOC(NULL, nodemask_size);
	new_nodes = SAFE_MALLOC(NULL, nodemask_size);

	memset(old_nodes, 0, nodemask_size);
	memset(new_nodes, 0, nodemask_size);
	for (i = 0; i < num_nodes; i++)
		set_bit(old_nodes, nodes[i], 1);
	set_bit(new_nodes, node, 1);

	TEST(ltp_syscall(__NR_migrate_pages, pid, max_node, old_nodes,
		new_nodes));
	if (TEST_RETURN != 0) {
		if (TEST_RETURN < 0)
			tst_resm(TFAIL | TERRNO, "migrate_pages failed "
				 "ret: %ld, ", TEST_RETURN);
		else
			tst_resm(TWARN, "migrate_pages could not migrate all "
				 "pages, not migrated: %ld", TEST_RETURN);
		print_mem_stats(pid, node);
	}
	free(old_nodes);
	free(new_nodes);
	return TEST_RETURN;
}
Ejemplo n.º 2
0
LOCAL void
out_of_memory (int which)
/* Report an out-of-memory error and stop execution */
/* If we compiled MEM_STATS support, report alloc requests before dying */
{
#ifdef MEM_STATS
  if (methods->trace_level <= 0) /* don't do it if free_all() will */
    print_mem_stats();		/* print optional memory usage statistics */
#endif
  ERREXIT1(methods, "Insufficient memory (case %d)", which);
}
Ejemplo n.º 3
0
static int check_addr_on_node(void *addr, int exp_node)
{
	int node;

	node = addr_on_node(addr);
	if (node == exp_node) {
		tst_resm(TPASS, "pid(%d) addr %p is on expected node: %d",
			 getpid(), addr, exp_node);
		return 0;
	} else {
		tst_resm(TFAIL, "pid(%d) addr %p not on expected node: %d "
			 ", expected %d", getpid(), addr, node, exp_node);
		print_mem_stats(0, exp_node);
		return 1;
	}
}
Ejemplo n.º 4
0
int print_perfstats(perf_stats* stats){
  if (print_platformID(stats) != 0) {
    printf("Error printing platformID\n");
  }
  if (print_name(stats) != 0) {
    printf("Error printing name\n");
  }
  if (print_mem_stats(stats) != 0) {
    printf("Error printing mem_stats\n");
  }
  if (print_cpu_stats(stats) != 0) {
    printf("Error printing cpu_stats\n");
  }
  if (print_logdrive_stats(stats) != 0) {
    printf("Error printing logdrive_stats\n");
  }
  if (print_networkadapter_stats(stats) != 0) {
    printf("Error printing networkadapter_stats\n");
  }
  if (print_process_stats(stats) != 0) {
    printf("Error printing process_stats\n");
  }
  
}
Ejemplo n.º 5
0
void my_memory_mgr::free_pool(int pool_id)
{
    small_pool_ptr shdr_ptr;
    large_pool_ptr lhdr_ptr;
    size_t space_freed;

    if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
        cinfo->ERREXIT1(JERR_BAD_POOL_ID, pool_id);	/* safety check */

#ifdef MEM_STATS
    if (cinfo->err->trace_level > 1)
        print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
#endif

    /* If freeing IMAGE pool, close any virtual arrays first */
    if (pool_id == JPOOL_IMAGE) {
        jvirt_sarray_ptr sptr;
        jvirt_barray_ptr bptr;

        for (sptr = virt_sarray_list; sptr != NULL; sptr = sptr->next) {
            if (sptr->b_s_open) {	/* there may be no backing store */
                sptr->b_s_open = FALSE;	/* prevent recursive close if error */
                (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
            }
        }
        virt_sarray_list = NULL;
        for (bptr = virt_barray_list; bptr != NULL; bptr = bptr->next) {
            if (bptr->b_s_open) {	/* there may be no backing store */
                bptr->b_s_open = FALSE;	/* prevent recursive close if error */
                (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
            }
        }
        virt_barray_list = NULL;
    }

    /* Release large objects */
    lhdr_ptr = large_list[pool_id];
    large_list[pool_id] = NULL;

    while (lhdr_ptr != NULL) {
        large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
        space_freed = lhdr_ptr->hdr.bytes_used +
                      lhdr_ptr->hdr.bytes_left +
                      sizeof(large_pool_hdr);
        free((void *) lhdr_ptr);
        total_space_allocated -= space_freed;
        lhdr_ptr = next_lhdr_ptr;
    }

    /* Release small objects */
    shdr_ptr = small_list[pool_id];
    small_list[pool_id] = NULL;

    while (shdr_ptr != NULL) {
        small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
        space_freed = shdr_ptr->hdr.bytes_used +
                      shdr_ptr->hdr.bytes_left +
                      sizeof(small_pool_hdr);
        free((void *) shdr_ptr);
        total_space_allocated -= space_freed;
        shdr_ptr = next_shdr_ptr;
    }
}
Ejemplo n.º 6
0
BOOL
pw_callback(process_info_t *pi, void **param)
{
    char *resstr;
    char reschar;
    int res;
    WCHAR buf[MAX_CMDLINE];
    DWORD version;
    BOOL under_dr;
    
    WCHAR qual_name[MAX_CMDLINE];
    if (exe)
        generate_process_name(pi, qual_name, BUFFER_SIZE_ELEMENTS(qual_name));

    if ( (pid && pi->ProcessID == pid) ||
         (exe && (!wcsicmp(wexe, pi->ProcessName) || !wcsicmp(wexe,  qual_name))) ||
         listall || listdr)
        {
            version = -1;
            res = under_dynamorio_ex(pi->ProcessID, &version);
            switch (res) {
            case DLL_PROFILE : resstr=NAME" profile"; reschar='P'; break;
            case DLL_RELEASE : resstr=NAME" release"; reschar='R'; break;
            case DLL_DEBUG : resstr=NAME" debug"; reschar='D'; break;
            case DLL_CUSTOM : resstr=NAME" custom"; reschar='C'; break;
            case DLL_NONE : resstr="native"; reschar='N'; break;
            case DLL_UNKNOWN : 
            default : resstr="<error>"; reschar='?';
            }

            under_dr = !(res == DLL_NONE || res == DLL_UNKNOWN);

            if (!listdr || under_dr) {
                if (!nopid && !showmem) {
                    if (onlypid)
                        fprintf(fp, "%d\n", (DWORD) pi->ProcessID);
                    else
                        fprintf(fp, "PID %d, ", (DWORD) pi->ProcessID);
                }
                if (!showmem && !onlypid) {
                    WCHAR qual_name[MAX_CMDLINE];
                    WCHAR *name_to_use = pi->ProcessName;
#ifdef X64
                    HANDLE hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, 
                                               (DWORD) pi->ProcessID);
                    if (is_wow64(hproc)) {
                        if (!no32)
                            fprintf(fp, "32-bit, ");
                        /* FIXME: currently x64 process can't see 32-bit
                         * drmarker
                         */
                        resstr="<unknown>";
                    }
                    CloseHandle(hproc);
#endif
                    if (!noqnames) {
                        generate_process_name(pi, qual_name,
                                              BUFFER_SIZE_ELEMENTS(qual_name));
                        name_to_use = qual_name;
                    }
                    fprintf(fp, "Process %S, ", name_to_use);
                    if (version == -1 || !showbuild)
                        fprintf(fp, "running %s\n", resstr);
                    else
                        fprintf(fp, "running %s (build %d)\n", resstr, version);
                }
                if (cmdline) {
                    res = get_process_cmdline(pi->ProcessID, buf,
                                              BUFFER_SIZE_ELEMENTS(buf));
                    NULL_TERMINATE_BUFFER(buf);
                    if (res == ERROR_SUCCESS) {
                        fprintf(fp, "\tCmdline: %S\n", buf);
                    }
                    else fprintf(fp, "\t<Cmdline err %d>\n", res);
                }
                if (qname) {
                    WCHAR cmdline[MAX_CMDLINE];
                    res = get_process_cmdline(pi->ProcessID, 
                                              cmdline, BUFFER_SIZE_ELEMENTS(cmdline));
                    NULL_TERMINATE_BUFFER(cmdline);
                    if (res == ERROR_SUCCESS) {
                        if (!get_commandline_qualifier(cmdline, buf,
                                                       BUFFER_SIZE_ELEMENTS(buf), !strip))
                            buf[0] = L'\0'; /* no args */
                        NULL_TERMINATE_BUFFER(buf);
                    }
                    if (res == ERROR_SUCCESS)
                        fprintf(fp, "\tQname: %S%s%S\n", pi->ProcessName,
                                buf[0] == L'\0' ? "" : "-", buf);
                    else 
                        fprintf(fp, "\t<Qname err %d>\n", res);
                    
                }
                if (under_dr && hotp) {
                    hotp_policy_status_table_t *status_tbl = NULL;
                    res = get_hotp_status(pi->ProcessID, &status_tbl);
                    if (res == ERROR_SUCCESS) {
                        uint j;
                        hotp_policy_status_t *cur;
                        fprintf(fp, "\tHotpatching:\n", res); 
                        for (j = 0; j < status_tbl->num_policies; j++) {
                            char status_buf[MAX_PATH];
                            cur = &(status_tbl->policy_status_array[j]);
                            if (get_status_string(status_buf, MAX_PATH,
                                                  cur->inject_status,
                                                  cur->mode))
                                fprintf(fp, "\t  Patch %s: %s\n",
                                        cur->policy_id, status_buf);
                        }
                    }
                    else if (res == ERROR_DRMARKER_ERROR) {
                        fprintf(fp, "\tHot Patching Not Enabled\n", res);
                    }
                    else {
                        fprintf(fp, "\t<Hotpatch Query Error %d>\n", res);
                    }
                }
                if (under_dr && showstats) {
                    dr_statistics_t *stats = get_dynamorio_stats(pi->ProcessID);
                    if (stats != NULL) {
                        uint i;
                        fprintf(fp, "\t%.*s\n",
                                BUFFER_SIZE_ELEMENTS(stats->process_name),
                                stats->process_name);
                        for (i = 0; i < stats->num_stats; i++) {
                            fprintf(fp, "\t%*.*s :%9d\n",
                                    BUFFER_SIZE_ELEMENTS(stats->stats[i].name),
                                    BUFFER_SIZE_ELEMENTS(stats->stats[i].name),
                                    stats->stats[i].name, stats->stats[i].value);
                        }
                    }
                    free_dynamorio_stats(stats);
                }
                if (showmem) {
                    print_mem_stats(pi, reschar, version);
                }
                count++;
            }
        } 
    return TRUE;
}