Example #1
0
void dbg_dump_cache(void)
{
	cache_image_t *p;
	dword c;

	cache_lock();
	p = ccacher.caches;

	for (c = 0; p != ccacher.caches + ccacher.caches_size; ++p) {
		if (p->status == CACHE_OK || p->status == CACHE_FAILED)
			c++;
	}

	dbg_printf(d, "CLIENT: Dumping cache[%u] %u/%ukb, %u finished",
			   ccacher.caches_size, (unsigned) ccacher.memory_usage / 1024,
			   (unsigned) get_free_mem() / 1024, (unsigned) c);

	for (p = ccacher.caches; p != ccacher.caches + ccacher.caches_size; ++p) {
		dbg_printf(d, "%d: %u st %u res %d mem %lukb", p - ccacher.caches,
				   (unsigned) p->selidx, p->status, p->result,
				   p->width * p->height * sizeof(pixel) / 1024L);
	}

	cache_unlock();
}
Example #2
0
void sys_monitor_ctrl_draw(gui_control __far * c)
{
    INT32S s[12];
    INT08S str[512];
    __int  i, x, y, x1, y1;

    x  = c->real_rect.x + 1;
    y  = c->real_rect.y + 1;
    x1 = c->real_rect.width + x - 2;
    y1 = c->real_rect.height + y - 2;

    if(c->flag & GUI_CTRL_FLAG_REFRESH){
        sprintf(str, "System Monitor");
        DrawFont(x+150, y, str, c->color, 2,  DRAW_OPT_FIL_BG);
        y += 56;
        sprintf(str, "handle  buf        btm        ptr          total    used     remain   state   prio   name ");
        DrawFont(x, y, str, c->color, 0,  DRAW_OPT_FIL_BG);
        y += 14;
        sprintf(str, "------------------------------------------------------------------------------------------");
        DrawFont(x, y, str, c->color, 0,  DRAW_OPT_FIL_BG);
        y += 14;
        for(i=0; i<MAX_TASKS; i++){
            if(TCBS[i].TcbUsed != TCB_USED_YES)continue;
            s[0] = (INT32S)TaskStackCheck(i, STACK_CHECK_OPT_GET_BUF);
            s[1] = (INT32S)TaskStackCheck(i, STACK_CHECK_OPT_GET_BTM);
            s[2] = (INT32S)TaskStackCheck(i, STACK_CHECK_OPT_GET_PTR);
            s[3] = (INT32S)TaskStackCheck(i, STACK_CHECK_OPT_TOTAL);
            s[4] = (INT32S)TaskStackCheck(i, STACK_CHECK_OPT_USED);
            s[5] = (INT32S)TaskStackCheck(i, STACK_CHECK_OPT_REMAIN);
            sprintf(str, "  %2d    %p  %p  %p    %-6ld   %-6ld %c %-6ld   %s   %-6d %s", 
                         i, s[0], s[1], s[2], s[3], s[4], ((s[5]<32L)?'*':' '), s[5], 
                         ((TCBS[i].TaskState==0)?"     ":"SLEEP"),
                         TCBS[i].Priority, TCBS[i].TaskName);/*lint !e559 !e622*/
            DrawFont(x, y, str, c->color, 0,  DRAW_OPT_FIL_BG);
            y += 14;
        }
        if(1){
            char aaa[32];
            sprintf(aaa, "CPU使用率: %3d%%", CPU_USED);
            DrawFont(x, y, aaa, 0, 0, DRAW_OPT_FIL_BG);
        }
        y+=14;
        sprintf(str, "tasks: %-4d free-memory: %-8ld  switches: %-8ld  seconds-from-start: %ld",
                     NumberOfTasks, get_free_mem(), TaskSwitches, SecondsFromStart);
        DrawFont(x, y, str, c->color, 0,  DRAW_OPT_FIL_BG);
        y += 14;
        sprintf(str, "------------------------------------------------------------------------------------------");
        DrawFont(x, y, str, c->color, 0,  DRAW_OPT_FIL_BG);
        y += 24;
        sprintf(str, "FamesOS "FamesOS_VersionString);
        DrawFont(x, y, str, 68, 2,  DRAW_OPT_FIL_BG);
        y += 50;
        sprintf(str, "我是中国人,hello, I am a chinese!");
        DrawFont(x, y, str, 98, 1,  DRAW_OPT_FIL_BG);
        DrawFont(x, y+16, str, 98, 0,  DRAW_OPT_FIL_BG);
        y += 50;
    }
}
Example #3
0
File: mm.c Project: deadbok/aMOS
int init_mm(void)
{
	print_message("Memory Manager...\n");
	enter_section();

	kernel_start=(unsigned long)&main;
	kernel_pages=ALIGN((((unsigned long)&end)-kernel_start), PAGE_SIZE)/PAGE_SIZE;

	print_message("Physical memory: ");
	physical_mem_size=probe_phys_mem();
	kprintf("%d Mb\n", physical_mem_size/1048576);

	print_message("Creating memory map...\n");
	init_mem_list();

	print_message("Free memory    : %d Mb\n", get_free_mem()/1048576);

	leave_section();
	print_message("");

	return(0);
}
Example #4
0
File: main.c Project: deadbok/aMOS
int main(void)
{
	init_pmm();

	if (init_mm())
		return(1);

	vid_init();

	vid_set_attr(FG_COLOR, RED);

	printf("\naMOS BOSS V.%s %s\n", STRING_VERSION, BUILD_ARCH);
	printf("Build %s %s by %s on %s\n\n", COMPILE_DATE, COMPILE_TIME, COMPILE_BY, COMPILE_HOST);

	vid_set_attr(FG_COLOR, WHITE);

	init_pit();

	init_tss();

	if (init_intr())
		return(1);

	init_cpu();

	if (init_sched())
		return(1);

	init_fd();

	printf("System memory: %d Mb\n\n", (int)pmm_get_size_mb());
	printf("Free kernel mem: %d bytes\nUsed kernel mem: %d bytes\n", (int)get_free_mem(), (int)get_used_mem());

	for (;;) {}
		
	return(0);
}
Example #5
0
void main()
{
  char s[200],cdir[200]="/",tmp[200];
  int a,b,ID=alloc_console();
  FILE *fp;
  meminit();
  fileinit();

  printf("ChaOS shell ID=%x\n",ID);

  do {
    printf(">");
    gets(s);

    if (!strcmp(s,"exit")) break;

    if (s[0]=='t'&&s[1]=='y'&&s[2]=='p'&&s[3]=='e'&&s[4]==' '){
        fp=fopen(s+5,"rb");
        while((a=fread(tmp,1,199,fp))) for (b=0;b<a;b++) putch(tmp[b]);
        fclose(fp);
        continue;
    }

    if (!strcmp(s,"dir")){
        showdir(cdir);continue;
    }

    if (!strcmp(s,"cls")){
       clrscr();
       continue;
    }

    if (s[0]=='c'&&s[1]=='d'&&s[2]==' '){
      if (s[3]=='.'&&s[4]=='.'&&s[5]==0){
         if (strlen(cdir)<=1) continue;
         b=strlen(cdir);b--;
         cdir[b]=0;
         for(b--;b>=0;b--) if (cdir[b]=='/'){ cdir[b+1]=0;break;}
         continue;
      }

      if (s[3]=='/')
         strcpy(tmp,s+3);
      else
         { strcpy(tmp,cdir);strcat(tmp,s+3);}
      if (tmp[strlen(tmp)-1]!='/') strcat(tmp,"/");
      if (strlen(tmp)>1){
        tmp[strlen(tmp)-1]=0;
        if (findfirst(tmp,&sr,_FF_NORMAL)==0){
           strcpy(cdir,tmp);strcat(cdir,"/");
        } else printf("not found: %s\n",tmp);
      } else strcpy(cdir,tmp);
      continue;
    }

    if (!strcmp(s,"mem")){
      printf("free = %i\n",get_free_mem()<<12);
      continue;
    }

    // Execute
    if (s[0]==0) continue;
    if (s[0]!='/'){ strcpy(tmp,cdir);strcat(tmp,s);strcpy(s,tmp); }
    if ((a=system(s))!=0)
       printf("not found: %s (%x)\n",s,a);

  } while(1);

  free_console(ID);
}
Example #6
0
int start_cache_next_image(void)
{
	cache_image_t *p = NULL;
	cache_image_t tmp;
	t_fs_filetype ft;
	dword free_memory;
	int fid;

	if (avoid_times && curr_times++ < avoid_times) {
//      dbg_printf(d, "%s: curr_times %d avoid time %d", __func__, curr_times, avoid_times);
		return -1;
	}

	free_memory = get_free_mem();

	if (config.scale >= 100) {
		if (free_memory < 8 * 1024 * 1024) {
			return -1;
		}
	} else if (free_memory < 1024 * 1024) {
		return -1;
	}

	cache_lock();

	for (p = ccacher.caches; p != ccacher.caches + ccacher.caches_size; ++p) {
		if (p->status == CACHE_INIT || p->status == CACHE_FAILED) {
			break;
		}
	}

	// if we ecounter FAILED cache, abort the caching, because user will quit when the image shows up
	if (p == ccacher.caches + ccacher.caches_size || p->status == CACHE_FAILED) {
		cache_unlock();
		return 0;
	}

	copy_cache_image(&tmp, p);
	cache_unlock();
	ft = fs_file_get_type(tmp.filename);
	fid = freq_enter_hotzone();

	if (tmp.where == scene_in_dir) {
		char fullpath[PATH_MAX];

		STRCPY_S(fullpath, tmp.archname);
		STRCAT_S(fullpath, tmp.filename);
		tmp.result =
			image_open_archive(fullpath, tmp.archname, ft, &tmp.width,
							   &tmp.height, &tmp.data, &tmp.bgc, tmp.where,
							   &tmp.exif_array);
	} else {
		tmp.result =
			image_open_archive(tmp.filename, tmp.archname, ft, &tmp.width,
							   &tmp.height, &tmp.data, &tmp.bgc, tmp.where,
							   &tmp.exif_array);
	}

	if (tmp.result == 0 && tmp.data != NULL && config.imgbrightness != 100) {
		pixel *t = tmp.data;
		short b = 100 - config.imgbrightness;
		dword i;

		for (i = 0; i < tmp.height * tmp.width; i++) {
			*t = disp_grayscale(*t, 0, 0, 0, b);
			t++;
		}
	}

	freq_leave(fid);

	cache_lock();

	for (p = ccacher.caches; p != ccacher.caches + ccacher.caches_size; ++p) {
		if (p->status == CACHE_INIT || p->status == CACHE_FAILED) {
			break;
		}
	}

	// recheck the first unloaded (and not failed) image, for we haven't locked cache for a while
	if (p == ccacher.caches + ccacher.caches_size || p->status == CACHE_FAILED) {
		free_cache_image(&tmp);
		cache_unlock();
		return 0;
	}

	if (tmp.result == 0) {
		dword memory_used;

		memory_used = tmp.width * tmp.height * sizeof(pixel);

//      dbg_printf(d, "SERVER: Image %u finished loading", (unsigned)tmp.selidx);
//      dbg_printf(d, "%s: Memory usage %uKB", __func__, (unsigned) ccacher.memory_usage / 1024);
		ccacher.memory_usage += memory_used;
		cacher_cleared = false;
		tmp.status = CACHE_OK;
		copy_cache_image(p, &tmp);
		tmp.data = NULL;
		tmp.exif_array = NULL;
		free_cache_image(&tmp);
		curr_times = avoid_times = 0;
	} else if ((tmp.result == 4 || tmp.result == 5)
			   || (tmp.where == scene_in_rar && tmp.result == 6)) {
		// out of memory
		// if unrar throwed a bad_cast exception when run out of memory, result can be 6 also.

		// is memory completely out of memory?
		if (ccacher.memory_usage == 0) {
//          dbg_printf(d, "SERVER: Image %u finished failed(%u), giving up", (unsigned)tmp.selidx, tmp.result);
			tmp.status = CACHE_FAILED;
			copy_cache_image(p, &tmp);
			p->data = NULL;
			p->exif_array = NULL;
		} else {
			// retry later
//          dbg_printf(d, "SERVER: Image %u finished failed(%u), retring", (unsigned)tmp.selidx, tmp.result);
//          dbg_printf(d, "%s: Memory usage %uKB", __func__, (unsigned) ccacher.memory_usage / 1024);
			if (avoid_times) {
				avoid_times *= 2;
			} else {
				avoid_times = 1;
			}

			avoid_times = min(avoid_times, 32767);
			curr_times = 0;
		}

		free_cache_image(&tmp);
	} else {
//      dbg_printf(d, "SERVER: Image %u finished failed(%u)", (unsigned)tmp.selidx, tmp.result);
		tmp.status = CACHE_FAILED;
		copy_cache_image(p, &tmp);
		p->data = NULL;
		p->exif_array = NULL;
		free_cache_image(&tmp);
	}

	cache_unlock();

	return 0;
}