Exemple #1
0
void	check_memory_map_event_c( void )
{
	check_memory( check_memory_map_event_c_map_event_func,
			"map-event.c: map_event_func" );
	check_memory( check_memory_map_event_c_map_event_pos,
			"map-event.c: map_event_pos" );
}
Exemple #2
0
void	check_memory_nest_flg_c( void )
{
	check_memory( check_memory_nest_flg_c_g_nest_flg,
			"nest-flg.c: g_nest_flg" );
	check_memory( check_memory_nest_flg_c_g_nest_flg_n,
			"nest-flg.c: g_nest_flg_n" );
}
Exemple #3
0
/*!
 * Marks memory as freed, optionally actually frees the memory
 *
 * @param memory pointer to memory
 * @param true_f 1 for actual freeing
 */
void _free_memory( void* memory, int true_f ) {
   struct Memory_handler* loop   = NULL;
   struct Memory_handler* loopm1 = NULL;
   loop = MEM_HANDLE;

   #ifdef DEBUG_MEMORY
      memory = memory - DEBUG_BUFFER_BORDER;
   #endif
   
   while(1)
   {
      if ( loop->mem == memory ) 
      {
         if (DEBUG > 1)
         {
            printf("(II) MemH: freeing memory from %p for %d, truefree: %d\n",
                   loop, loop->size, true_f  );
         }
         
         #ifdef DEBUG_MEMORY
            check_memory( loop->mem );
            check_memory( loop->mem + DEBUG_BUFFER_BORDER + loop->true_size );
         #endif
         /* do we do the actual freeing */
         if ( true_f )
         {
            free ( loop->mem );
            /* and we got to free also the memory handler
             * memory, if this is not the root node.
             */
            loop->mem = NULL;
            loop->used = -1;
            loop->size = 0;
            
            if (loopm1 != NULL)
            {
               loopm1->next = loop->next;
               free(loop);
               return;
            }
         }
         else
         {
            loop->used = 0;
            return;
         }
      }
      
      if (loop->next == NULL)
         break;

      loopm1 = loop;
      loop = loop->next;
   }
   printf("(WW) Memory handler: did not find memory to be freed\n");
}
Exemple #4
0
int find_delta_run(int page_delta,void* addr1){
  // Importantly, we chose the values of X and Y so that they map to the same
  // bank, but to different rows within the bank (see paper)
  // Choose some addresses, then run the test on them
  // We want a delta of PHYS_PAGE_DELTA pages

  void *addr2;
  unsigned long long phys1,phys2;
  int j, delta;

  phys1 = _read_pagemap(addr1);
  if(phys1 <= 0){
    printf("Error getting pagemap1\n");
    exit(1);
  }
  for(j=0;j<PAGES;j++){
    addr2 = &(memory[PAGE_SIZE*j]);
    phys2 = _read_pagemap(addr2);
    if(phys2 <= 0){
      printf("Error getting pagemap2\n");
      exit(1);
    }
    if(abs(phys1 - phys2) == page_delta ){
      printf("[Info] Running with addresses(pfn): "
             "%p(%lld), %p(%lld)\n",
             addr1,phys1,addr2,phys2);
      loop(addr1,addr2,NUM_ITERS);
      check_memory();
      return 1;
    }
  }
  return 0;
}
Exemple #5
0
void SLdebug_free (SLFUTURE_VOID *p)
{
   if (p == NULL) return;
   if (-1 == check_memory ((unsigned char *) p, "FREE")) return;

   SLFREE ((char*)p - Chunk);
}
Exemple #6
0
int main() {
  Memory_word program[MEMORY_SIZE]= {0};
  Int_register reg[NUM_REGISTERS]= {0};
  Float_register freg[NUM_REGISTERS]= {0.0};
  char *filename= "public03.a";
  int num_instructions;
  State status;
  int q;

  num_instructions= assemble(filename, program, 0);

  if (num_instructions == 0)
    printf("Couldn't assemble \"%s\", exiting.\n", filename);
  else {

    status= run(program, reg, freg, -1, -1);

    if (status != FINISHED)
      printf("\nError - run() returned status %d.\n", status);
    else {
      printf("Integer Registers:\n");
      for (q= 0; q < NUM_REGISTERS; q++)
        printf("Register R%02d: %d\n", q, reg[q]);
      printf("\n");
      printf("Float Registers:\n");
      for (q= 0; q < NUM_REGISTERS; q++)
        printf("Register F%02d: %f\n", q, freg[q]);
      printf("\n");
      printf("Memory:\n");
      check_memory(program, (num_instructions + 1) * BYTES_PER_WORD);
    }
  }

  return 0;
}
Exemple #7
0
struct vector* vector_new(int length) {
    assert(length >= 0);

    struct vector* new_vector = malloc(sizeof(struct vector));
    check_memory((void*) new_vector);

    DATA(new_vector) = malloc((sizeof(double)) * length);
    check_memory((void*) DATA(new_vector));

    new_vector->length = length;
    OWNS_MEMORY(new_vector)= true;
    MEMORY_OWNER(new_vector) = NULL;
    REF_COUNT(new_vector) = 0;

    return new_vector;
}
Exemple #8
0
/* Create a new vector which is a *view* into an already existing vector. 

   The new and parent vectors share the same data, and modifying the data in
   either will modify both vectors.  One the other hand, we do not have to copy
   any data to create a view.
*/
struct vector* vector_new_view(struct linalg_obj* parent, double* view, int length) {
    assert(length >= 0);
    // TODO: Make this view check work.
    /* Check that pointers to the beginning and end of view vector live
       within the data segment of the parent object.

       This doesn't work because matricies have no length.  This could be
       a property of linalg_obj, but then a macro would be needed to
       make the lookup type generic.
       
    assert(DATA(parent) <= view && view < DATA(parent) + parent->length);
    assert(view + length <= DATA(parent) + parent->length);
    */

    struct vector* new_vector = malloc(sizeof(struct vector));
    check_memory((void*)new_vector);

    DATA(new_vector) = view;
    new_vector->length = length;
    OWNS_MEMORY(new_vector) = false;
    MEMORY_OWNER(new_vector) = parent;
    REF_COUNT(new_vector) = 0;
    REF_COUNT(parent) += 1;

    return new_vector;
}
Exemple #9
0
std::string
impl::check_requirements(const atf::tests::vars_map& metadata,
                         const atf::tests::vars_map& config)
{
    std::string failure_reason = "";

    for (atf::tests::vars_map::const_iterator iter = metadata.begin();
         failure_reason.empty() && iter != metadata.end(); iter++) {
        const std::string& name = (*iter).first;
        const std::string& value = (*iter).second;
        INV(!value.empty()); // Enforced by application/X-atf-tp parser.

        if (name == "require.arch")
            failure_reason = check_arch(value);
        else if (name == "require.config")
            failure_reason = check_config(value, config);
        else if (name == "require.files")
            failure_reason = check_files(value);
        else if (name == "require.machine")
            failure_reason = check_machine(value);
        else if (name == "require.memory")
            failure_reason = check_memory(value);
        else if (name == "require.progs")
            failure_reason = check_progs(value);
        else if (name == "require.user")
            failure_reason = check_user(value, config);
        else {
            // Unknown require.* properties are forbidden by the
            // application/X-atf-tp parser.
            INV(failure_reason.find("require.") != 0);
        }
    }

    return failure_reason;
}
Exemple #10
0
void mattr_release(mattr_t *mattr) {
    check_memory(mattr);

    //mattr->fid XXX fid not initialized.
    mattr->cid = UINT16_MAX;
    memset(mattr->sids, 0, ROZOFS_SAFE_MAX);
}
Exemple #11
0
SLFUTURE_VOID *SLdebug_realloc (SLFUTURE_VOID *p, unsigned long n)
{
   if (-1 == check_memory ((unsigned char *) p, "REALLOC")) return NULL;
   if ((p = (char *) SLREALLOC ((char*)p - Chunk, n + 2 * Chunk)) == NULL) return NULL;
   fixup ((unsigned char *) p, n, "REALLOC");
   return (SLFUTURE_VOID *) ((char*)p + Chunk);
}
Exemple #12
0
void env_init()
{
	clrscr();
	move_cursor(0,0);
	setup_hw();
	puts("Ben OS v"BOS_VERSION" starting...\n");
	puts(msg_boot32ok);
	check_memory();
	floppy = get_floppy_info();
}
Exemple #13
0
/* returns:  0: one check passed,  1: all not passed */
static inline i32 or_check_memory (CheckEntry *chk_en, value_t *chk_buf)
{
	i32 ret;
	u32 i = 0;

	do {
		ret = check_memory(chk_en, chk_buf, i);
	} while (ret && chk_en->check[++i] != CHECK_END);

	return ret;
}
Exemple #14
0
void erts_check_for_holes(Process* p)
{
    ErlHeapFragment* hf;
    Eterm* start;

    if (p->flags & F_DISABLE_GC)
	return;

    start = p->last_htop ? p->last_htop : HEAP_START(p);
    check_memory(start, HEAP_TOP(p));
    p->last_htop = HEAP_TOP(p);

    for (hf = MBUF(p); hf != 0; hf = hf->next) {
	if (hf == p->last_mbuf) {
	    break;
	}
	check_memory(hf->mem, hf->mem+hf->used_size);
    }
    p->last_mbuf = MBUF(p);
}
Exemple #15
0
static ssize_t driver_write(struct file *instance, const char __user * userbuf, size_t count, loff_t * off)
{
	private_data *data = (private_data *) instance->private_data;

	if (data->write_data == NULL) {
		data->write_data = (write_data *) kmalloc(sizeof(write_data), GFP_KERNEL);
		check_memory(data->write_data);

		pr_debug("Create producer thread for the first time...\n");
	}

	data->write_data->count = count;
	pr_debug("Write: Call wake_up_process()\n");

	data->write_data->thread_write = kthread_create(thread_write, data, "thread_write");
	check_if_thread_is_valid(data->write_data->thread_write);

	pr_debug("Write: bytes to copy: %d\n", count);
	
	data->write_data->user = kmalloc(count + 1, GFP_KERNEL);
	check_memory(data->write_data->user);
	
	if (copy_from_user(data->write_data->user, userbuf, count) != 0) {
		pr_crit("Could not copy from user space!!!\n");
		return -1;
	}

	data->write_data->user[count] = '\0';

	wake_up_process(data->write_data->thread_write);
	wait_for_completion(&data->on_exit);

	pr_debug("Wake consumer up...\n");

	wake_up_interruptible(&wq_read);

	return count;
}
Exemple #16
0
INT wmain(INT argc, WCHAR **argv)
{
	printInfoStruct printInfo = {};
	po::variables_map vm;

	INT ret = parseArguments(argc, argv, vm, printInfo);
	if (ret != -1)
		return ret;

	ret = check_memory(printInfo);
	if (ret != -1)
		return ret;

	return printOutput(printInfo);
}
Exemple #17
0
string cmd(string unused) {
    string ret = "";
    if(efun_exists("check_memory")){
#ifdef __DEBUGMALLOC__
#ifdef __DEBUGMALLOC_EXTENSIONS__
#ifdef __PACKAGE_DEVELOP__
        ret = check_memory(1);
#endif
#endif
#endif
        write("%^RED%^The output for this command may be misleading. It is kept "+
          "as a historical curiosity, but is not necessarily reliable.%^RESET%^");
        if(sizeof(ret) < 7000) write(ret);
        else {
            this_player()->eventPage(({ret}));
        }
Exemple #18
0
/******************************************************************************

  General linear least squares fit routine 
  from section 15.4 of Numerical Recipes.

  yfit(x) = function which fills f[i],i=0..o-1 with the o 
            fitting functions evaluated at x.
  fom = if nonzero figure-of-merit is returned here.	    
  a  = fitting parameters
  av = if (av) error variances for the fitting parameters returned here.
  x  = n abscissas
  y  = n ordinates
  ys = if (ys) = n error standard deviations for y values
  tol = smallest fraction of maximum singular value (eigenvalues, roughly) 
        which a small singular value can equal -- smaller values are
        set to zero, assumed to indicate redundancy.  NR suggests
        of order 10^-6
  n = number of abscissas.
  o = number of fitting parameters.

  */
static fit_rc fit_lsq(void (*yfit)(), double *fom, double *a, double *av,
		      const double *x, const double *y, const double *ys,
		      double tol, int n, int o) {

  double wmax,wmin,xsq,sum ;
  int i,j ;
  const char *me = "fit_lsq" ;

  if (check_memory(o,n) != OK) return(memfail(__LINE__,me)) ;

  for(i=0;i<n;i++) {
    yfit(x[i]) ;
    for(j=0;j<o;j++) u[i][j] = f[j] * (ys ? 1.0/ys[i] : 1.0) ;
  } ;
  memcpy(b,y,n*sizeof(double)) ;
  if (ys) for(i=0;i<n;i++) b[i] /= ys[i] ;

  if (svdcmp(u,n,o) != OK)
    return(punt(__LINE__,me,"singular value decomposition failed.")) ;

  wmax = 0.0 ;
  for(wmax=0.0,j=0;j<o;j++) if (w[j] > wmax) wmax = w[j] ;
  wmin = tol * wmax ;
  for(j=0;j<o;j++) if (w[j] < wmin) w[j] = 0.0 ;
  
  if (svbksb(a,n,o) != OK) 
    return(punt(__LINE__,me,"back substitution failed.")) ;

  if (av) {
    if (svdvar(o) != OK)
      return(punt(__LINE__,me,"variance calculation failed.")) ;
    for(i=0;i<o;i++) av[i] = cvm[i][i] ;
  } ;
  if (fom) {
    xsq = 0.0 ;
    for(i=0;i<o;i++) {
      yfit(x[i]) ;
      sum = 0.0 ;
      for(j=0;j<o;j++) sum += a[j] * f[j] ;
      sum = (y[i] - sum)/(ys ? ys[i]*ys[i] : 1.0) ;
      xsq += sum*sum ;
    } ;
    *fom = xsq ;
  } ;
  
  return(OK) ;
}
Exemple #19
0
void	check_memory_replay_c( void )
{
	check_memory( check_memory_replay_c_g_replay_save_slot,
			"replay.c: g_replay_save_slot" );
	check_memory( check_memory_replay_c_g_flg_reg_replay,
			"replay.c: g_flg_reg_replay" );
	check_memory( check_memory_replay_c_g_replay_randm_seed,
			"replay.c: g_replay_randm_seed" );
	check_memory( check_memory_replay_c_g_replay_head,
			"replay.c: g_replay_head" );
	check_memory( check_memory_replay_c_g_replay_cur,
			"replay.c: g_replay_cur" );
	check_memory( check_memory_replay_c_g_replay_cur_draw,
			"replay.c: g_replay_cur_draw" );
	check_memory( check_memory_replay_c_g_flg_play_replay,
			"replay.c: g_flg_play_replay" );
	check_memory( check_memory_replay_c_g_play_replay_idx,
			"replay.c: g_play_replay_idx" );
}
Exemple #20
0
void	check_memory_ending_space_c( void )
{
	check_memory( check_memory_ending_space_c_XR,
			"ending-space.c: XR" );
	check_memory( check_memory_ending_space_c_g_space,
			"ending-space.c: g_space" );
	check_memory( check_memory_ending_space_c_g_frame,
			"ending-space.c: g_frame" );
	check_memory( check_memory_ending_space_c_staff_roll_interval_width,
			"ending-space.c: staff_roll_interval_width" );
	check_memory( check_memory_ending_space_c_staff_roll_y,
			"ending-space.c: staff_roll_y" );
	check_memory( check_memory_ending_space_c_FLICKER_N,
			"ending-space.c: FLICKER_N" );
	check_memory( check_memory_ending_space_c_g_str_staff_roll,
			"ending-space.c: g_str_staff_roll" );
	check_memory( check_memory_ending_space_c_g_str_the_end,
			"ending-space.c: g_str_the_end" );
}
Exemple #21
0
void print_used_memory(void)
{
#if defined DEBUG_EASDK && defined EASDK_DEBUG_LEVEL_DEBUG
#if defined __APPLE__
    struct mstats stat;

    stat = mstats();
    debug_log(DEBUG_MEM, ("Memstat: %d\n", stat.bytes_used));
#elif defined __linux__
    struct mallinfo mi;

    mi = mallinfo();
    debug_log(DEBUG_MEM, ("Memstat: %d(/%d)\n", mi.uordblks, mi.fordblks));
#endif
    print_peak_memory_usage();
    check_memory();
    print_memory_stats();
#endif
}
Exemple #22
0
static ssize_t driver_read(struct file *instance, char *user, size_t count, loff_t * offset)
{
	unsigned long not_copied, to_copy, copied;
	private_data *data = (private_data *) instance->private_data;
	wait_queue_head_t *wait_queue;
	atomic_t *wake_up;

	if (data->read_data == NULL) {
		data->read_data = (read_data *) kmalloc(sizeof(read_data), GFP_KERNEL);
		check_memory(data->read_data);

		init_waitqueue_head(&data->read_data->wait_queue);
		INIT_WORK(&data->work, thread_read);
		pr_debug("Create consumer thread for the first time...\n");
	}
	// Init read_data
	wait_queue = &data->read_data->wait_queue;
	wake_up = &data->read_data->wake_up;

	atomic_set(wake_up, 0);

	if (!queue_work(worker_queue, &data->work)) {
		pr_crit("queue_work not successful ...\n");
	}

	if (wait_event_interruptible(*wait_queue, atomic_read(wake_up)))
		return -ERESTART;


	if (data->ret < 0) {
		return data->ret;
	}

	to_copy = data->ret;
	not_copied = copy_to_user(user, data->read_data->user, to_copy);
	copied = to_copy - not_copied;

	pr_debug("not_copied: %lu to_copy: %lu. count %d. %lu bytes read\n", not_copied, to_copy, count, copied);

	kfree(data->read_data->user);

	return copied;
}
Exemple #23
0
static int driver_open(struct inode *inode, struct file *instance)
{
	private_data *data;

	printk("open() called!\n");

	data = (private_data *) kmalloc(sizeof(private_data), GFP_KERNEL);
	check_memory(data);

	init_completion(&(data->on_exit));

	// Do only kmalloc() on read() and write, if write_data or read_data are NULL!
	data->write_data = NULL;
	data->read_data = NULL;

	instance->private_data = data;

	return 0;
}
Exemple #24
0
    expr apply(expr const & e, unsigned offset) {
        bool shared = false;
        if (m_use_cache && is_shared(e)) {
            if (auto r = m_cache->find(e, offset))
                return *r;
            shared = true;
        }
        check_interrupted();
        check_memory("replace");

        if (optional<expr> r = m_f(e, offset)) {
            return save_result(e, offset, *r, shared);
        } else {
            switch (e.kind()) {
            case expr_kind::Constant: case expr_kind::Sort: case expr_kind::Var:
                return save_result(e, offset, e, shared);
            case expr_kind::Meta:     case expr_kind::Local: {
                expr new_t = apply(mlocal_type(e), offset);
                return save_result(e, offset, update_mlocal(e, new_t), shared);
            }
            case expr_kind::App: {
                expr new_f = apply(app_fn(e), offset);
                expr new_a = apply(app_arg(e), offset);
                return save_result(e, offset, update_app(e, new_f, new_a), shared);
            }
            case expr_kind::Pi: case expr_kind::Lambda: {
                expr new_d = apply(binding_domain(e), offset);
                expr new_b = apply(binding_body(e), offset+1);
                return save_result(e, offset, update_binding(e, new_d, new_b), shared);
            }
            case expr_kind::Macro: {
                buffer<expr> new_args;
                unsigned nargs = macro_num_args(e);
                for (unsigned i = 0; i < nargs; i++)
                    new_args.push_back(apply(macro_arg(e, i), offset));
                return save_result(e, offset, update_macro(e, new_args.size(), new_args.data()), shared);
            }}
            lean_unreachable();
        }
    }
Exemple #25
0
/*
 * Detect the rest of the memory available on this device.
 */
void detect_memory_rest(struct ExecBase * SysBase)
{
	int c = 0;
	*(ULONG *)(2*4) = (ULONG)dm_bus_error_handler;
	*(ULONG *)(3*4) = (ULONG)dm_addr_error_handler;

	while (0 != memory[c].start) {
		UBYTE * end;
		/*
		 * Now try to detect sram size
		 */
		end = check_memory(memory[c].start);
		if (end != memory->start[c] && NULL != end) {
			AddMemList((ULONG)end-(ULONG)memory[c].start,
			           MEMF_CHIP | MEMF_PUBLIC | MEMF_LOCAL | MEMF_24BITDMA | MEMF_KICK,
			           memory[c].pri,
			           memory[c].start,
			           "fast memory");
		}
		c++;
	}
}
Exemple #26
0
int myNpDrmRenameCheck(char *fn)
{
	int ret;
	
	// don't worry, it works without setting $k1 to 0
	if (sceKernelFindModuleByName("scePspNpDrm_Driver") == NULL) {
		ret = 0x8002013A;
		goto exit;
	}

	if(!check_memory(fn, strlen(fn) + 1)) {
		ret = 0x80550910;
		goto exit;
	}

	ret = check_file_is_encrypted_by_path(fn);

	if (ret == 0) {
		SceIoStat stat;
		u32 k1;
		
		k1 = pspSdkSetK1(0);
		ret = sceIoGetstat(fn, &stat) == 0 ? 0 : 0x80550901;
		pspSdkSetK1(k1);
	} else {
		if (_sceNpDrmRenameCheck != NULL) {
			ret = (*_sceNpDrmRenameCheck)(fn);
		} else {
			ret = 0x8002013A;
		}
	}

exit:
	printk("%s: %s -> 0x%08X\n", __func__, fn, ret);

	return ret;
}
Exemple #27
0
/*
 * Detect some initial memory. This should be enough
 * to get the OS up and running. More detection follows
 * later...
 */
struct MemHeader * detect_memory(void)
{
	struct MemHeader * mh;
	/*
	 * There is no SysBase available here!!
	 * It has not been initialized, yet.
	 */

	/*
	 * Must initialize the BusError handler
	 */
	UBYTE * address = (UBYTE *)1024;

	*(ULONG *)(2*4) = (ULONG)dm_bus_error_handler;
	*(ULONG *)(3*4) = (ULONG)dm_addr_error_handler;

	address = check_memory(address);

	mh=(struct MemHeader*)MEM_START;
	mh->mh_Node.ln_Succ    = NULL;
	mh->mh_Node.ln_Pred    = NULL;
	mh->mh_Node.ln_Type    = NT_MEMORY;
	mh->mh_Node.ln_Name    = "chip memory";
	mh->mh_Node.ln_Pri     = -5;
	mh->mh_Attributes      = MEMF_CHIP | MEMF_PUBLIC | MEMF_LOCAL | MEMF_24BITDMA |
	                         MEMF_KICK;
	mh->mh_First           = (struct MemChunk *)((UBYTE*)mh+MEMHEADER_TOTAL);
	mh->mh_First->mc_Next  = NULL;
	mh->mh_First->mc_Bytes = ((ULONG)address - MEM_START) - MEMHEADER_TOTAL;

	mh->mh_Lower           = mh->mh_First;
	mh->mh_Upper           = (APTR)(address);
	mh->mh_Free            = mh->mh_First->mc_Bytes;

	return mh;
}
int main(int argc, char *argv[])
{
  int time;
  char method[SCREEN_UPDATE_STR_LEN];
  char fps_text[16];
  
  if (argc > 1) {
    if (strstr(argv[1], "help")) {
      printf("Type \"kwestkingdom\" to play!\n");
      exit(0);
    }
  }

  if (!init_kwestkingdom()) {
    return 1;
  }

  init_engine();

  /**
   * Reset the timers just before the game begins.
   */
  reset_timer();

  /**
   * BEGIN MAIN LOOP
   */
  while (!quitting) {

    while (get_ticks() == 0) {
      rest(1);
    }

    while (get_ticks() > 0) {

      time = get_ticks();

      /**
       * UPDATE
       */
      update_engine();

      decrease_timer();

      if (time <= get_ticks()) {
        break;
      }

    }

    /**
     * DRAW
     */
    paint_engine(grab_canvas());

    /**
     * Show FPS
     */
    sprintf(fps_text, "FPS %d", get_fps());
    show_text(grab_canvas(), fps_text, 10, 10, WHITE, BLACK);

    /**
     * Show the method of screen updating.
     */
    find_screen_update_method(method);

    show_text(
      grab_canvas(),
      method,
      grab_tile_size() / 5, /* x */
      grab_canvas_height() - (grab_tile_size() / 2), /* y */
      WHITE,
      BLACK
    );

    /**
     * Show all of the new screen changes
     */
    refresh_screen();

    mark_frame_complete();
  }
  /**
   * END MAIN LOOP
   */

  /**
   * Cleanup
   */
  stop_engine();
  stop_screen();
  stop_resources();
  
  check_memory();
  
  return 0;
}
Exemple #29
0
// Fast checks (no DB access) to see if the job can be sent to the host.
// Reasons why not include:
// 1) the host doesn't have enough memory;
// 2) the host doesn't have enough disk space;
// 3) based on CPU speed, resource share and estimated delay,
//    the host probably won't get the result done within the delay bound
// 4) app isn't in user's "approved apps" list
//
// If the job is feasible, return 0 and fill in wu.delay_bound
// with the delay bound we've decided to use.
//
int wu_is_infeasible_fast(
    WORKUNIT& wu,
    int res_server_state, int res_priority, double res_report_deadline,
    APP& app, BEST_APP_VERSION& bav
) {
    int retval;

    // project-specific check
    //
    if (wu_is_infeasible_custom(wu, app, bav)) {
        return INFEASIBLE_CUSTOM;
    }

    if (config.user_filter) {
        if (wu.batch && wu.batch != g_reply->user.id) {
            return INFEASIBLE_USER_FILTER;
        }
    }

    // homogeneous redundancy: can't send if app uses HR and
    // 1) host is of unknown HR class, or
    // 2) WU is already committed to different HR class
    //
    if (app_hr_type(app)) {
        if (hr_unknown_class(g_reply->host, app_hr_type(app))) {
            if (config.debug_send) {
                log_messages.printf(MSG_NORMAL,
                    "[send] [HOST#%d] [WU#%u %s] host is of unknown class in HR type %d\n",
                    g_reply->host.id, wu.id, wu.name, app_hr_type(app)
                );
            }
            return INFEASIBLE_HR;
        }
        if (already_sent_to_different_hr_class(wu, app)) {
            if (config.debug_send) {
                log_messages.printf(MSG_NORMAL,
                    "[send] [HOST#%d] [WU#%u %s] failed quick HR check: WU is class %d, host is class %d\n",
                    g_reply->host.id, wu.id, wu.name, wu.hr_class, hr_class(g_request->host, app_hr_type(app))
                );
            }
            return INFEASIBLE_HR;
        }
    }

    // homogeneous app version
    //
    if (app.homogeneous_app_version) {
        int avid = wu.app_version_id;
        if (avid && bav.avp->id != avid) {
            if (config.debug_send) {
                log_messages.printf(MSG_NORMAL,
                    "[send] [HOST#%d] [WU#%u %s] failed homogeneous app version check: %d %d\n",
                    g_reply->host.id, wu.id, wu.name, avid, bav.avp->id
                );
            }
            return INFEASIBLE_HAV;
        }
    }

    if (config.one_result_per_user_per_wu || config.one_result_per_host_per_wu) {
        if (wu_already_in_reply(wu)) {
            return INFEASIBLE_DUP;
        }
    }

    retval = check_memory(wu);
    if (retval) return retval;
    retval = check_disk(wu);
    if (retval) return retval;
    retval = check_bandwidth(wu);
    if (retval) return retval;

    if (app.non_cpu_intensive) {
        return 0;
    }

    // do deadline check last because EDF sim uses some CPU
    //
    double opt, pess;
    get_delay_bound_range(
        wu, res_server_state, res_priority, res_report_deadline, bav, opt, pess
    );
    wu.delay_bound = (int)opt;
    if (opt == 0) {
        // this is a resend; skip deadline check
        return 0;
    }
    retval = check_deadline(wu, app, bav);
    if (retval && (opt != pess)) {
        wu.delay_bound = (int)pess;
        retval = check_deadline(wu, app, bav);
    }
    return retval;
}
Exemple #30
0
void modem_process(struct modem *mdm)
{
	struct sms_msg    *sms_messg;
	struct incame_sms sms;
	struct network *net;
	int i,k,len;
	int counter;
	int dont_wait;
	int empty_pipe;
	int cpms_unsupported;
	int max_mem=0, used_mem=0;

	sms_messg = 0;
	cpms_unsupported = 0;

	/* let's open/init the modem */
	LM_DBG("opening modem\n");
	if (openmodem(mdm)==-1) {
		LM_ERR("failed to open modem %s! %s \n",
			mdm->name,strerror(errno));
		return;
	}

	setmodemparams(mdm);
	initmodem(mdm,check_cds_report);

	if ( (max_mem=check_memory(mdm,MAX_MEM))==-1 ) {
		LM_WARN("CPMS command unsupported! using default values (10,10)\n");
		used_mem = max_mem = 10;
		cpms_unsupported = 1;
	}
	LM_DBG("modem maximum memory is %d\n",max_mem);

	set_gettime_function();

	while(1)
	{
		/* update the local config */
		cfg_update();

		dont_wait = 0;
		for (i=0;i<nr_of_networks && mdm->net_list[i]!=-1;i++)
		{
			counter = 0;
			empty_pipe = 0;
			net = &(networks[mdm->net_list[i]]);
			/*getting msgs from pipe*/
			while( counter<net->max_sms_per_call && !empty_pipe )
			{
				/* let's read a sms from pipe */
				len = read(net->pipe_out, &sms_messg,
					sizeof(sms_messg));
				if (len!=sizeof(sms_messg)) {
					if (len>=0)
						LM_ERR("truncated message read from pipe!"
								" -> discarded\n");
					else if (errno==EAGAIN)
						empty_pipe = 1;
					else
						LM_ERR("pipe reading failed: %s\n",strerror(errno));
					sleep(1);
					counter++;
					continue;
				}
				(*queued_msgs)--;

				/* compute and send the sms */
				LM_DBG("%s processing sms for net %s:"
					" \n\tTo:[%.*s]\n\tBody=<%d>[%.*s]\n",
					mdm->device, net->name,
					sms_messg->to.len,sms_messg->to.s,
					sms_messg->text.len,sms_messg->text.len,sms_messg->text.s);
				send_as_sms( sms_messg , mdm);

				counter++;
				/* if I reached the limit -> set not to wait */
				if (counter==net->max_sms_per_call)
					dont_wait = 1;
			}/*while*/
		}/*for*/

		/* let's see if we have incoming sms */
		if ( !cpms_unsupported )
			if ((used_mem = check_memory(mdm,USED_MEM))==-1) {
				LM_ERR("CPMS command failed! cannot get used mem -> using 10\n");
				used_mem = 10;
			}

		/* if any, let's get them */
		if (used_mem)
			LM_DBG("%d new SMS on modem\n",used_mem);
			for(i=1,k=1;k<=used_mem && i<=max_mem;i++) {
				if (getsms(&sms,mdm,i)!=-1) {
					k++;
					LM_DBG("SMS Get from location %d\n",i);
					/*for test ;-) ->  to be remove*/
					LM_DBG("SMS RECEIVED:\n\rFrom: %s %s\n\r%.*s %.*s"
						"\n\r\"%.*s\"\n\r",sms.sender,sms.name,
						DATE_LEN,sms.date,TIME_LEN,sms.time,
						sms.userdatalength,sms.ascii);
					if (!sms.is_statusreport)
						_send_sms_as_sip(&sms, mdm);
					else 
						check_sms_report(&sms);
				}
			}

		/* if reports are used, checks for expired records in report queue */
		if (sms_report_type!=NO_REPORT)
			check_timeout_in_report_queue();

		/* sleep -> if it's needed */
		if (!dont_wait) {
				sleep(mdm->looping_interval);
		}
	}/*while*/
}