Esempio n. 1
0
    /**
     * \return Gaussian second centered moment
     *
     * Computes the covariance from other representation of not available
     *
     * \throws GaussianUninitializedException if the Gaussian is of dynamic-size
     *         and has not been initialized using SetStandard(dimension).
     * \throws InvalidGaussianRepresentationException if non-of theember function)
     *         representation can be used as a source
     */
    virtual const SecondMoment& covariance() const
    {
        if (dimension() == 0)
        {
            fl_throw(GaussianUninitializedException());
        }

        if (is_dirty(CovarianceMatrix) && is_dirty(DiagonalCovarianceMatrix))
        {
            switch (select_first_representation<4>({{DiagonalSquareRootMatrix,
                                                    DiagonalPrecisionMatrix,
                                                    SquareRootMatrix,
                                                    PrecisionMatrix}}))
            {
            case SquareRootMatrix:
                covariance_ = square_root_ * square_root_.transpose();
                break;

            case PrecisionMatrix:
                covariance_ = precision_.inverse();
                break;

            case DiagonalSquareRootMatrix:
                covariance_.setZero(dimension(), dimension());
                for (int i = 0; i < square_root_.diagonalSize(); ++i)
                {
                    covariance_(i, i) = square_root_(i, i) * square_root_(i, i);
                }
                break;

            case DiagonalPrecisionMatrix:
                covariance_.setZero(dimension(), dimension());
                for (int i = 0; i < precision_.diagonalSize(); ++i)
                {
                    covariance_(i, i) = 1./precision_(i, i);
                }
                break;

            default:
                fl_throw(InvalidGaussianRepresentationException());
                break;
            }

            updated_internally(CovarianceMatrix);
        }

        return covariance_;
    }
Esempio n. 2
0
 Attribute select_first_representation(
     const std::array<Attribute, AttributeCount>& representations
 ) const noexcept
 {
     for (auto& rep: representations)  if (!is_dirty(rep)) return rep;
     return Attributes;
 }
Esempio n. 3
0
bool RedScreen::_invalidate(const SpiceRect& rect, bool urgent, uint64_t& update_mark)
{
    RecurciveLock lock(_update_lock);
    bool update_triger = !is_dirty() && (urgent || !_periodic_update);
    region_add(&_dirty_region, &rect);
    update_mark = _update_mark;
    return update_triger;
}
Esempio n. 4
0
    /**
     * \return Covariance determinant
     *
     * \throws see covariance
     */
    virtual Real covariance_determinant() const
    {
        if (is_dirty(Determinant))
        {
            determinant_ = covariance().determinant();

            updated_internally(Determinant);
        }

        return determinant_;
    }
Esempio n. 5
0
void slot_flush(int n)
{
    if (n < 0 || n >= NUM_SLOTS)
        return;

    slot_t *slot = slots[n];
    if (slot != NULL && is_dirty(slot))
    {
        // TODO: Save to disk & reset dirty-flag
        slot->flags &= ~SLOT_DIRTY;
    }
}
Esempio n. 6
0
    /**
     * \return True if the covariance matrix has a full rank
     *
     * \throws see covariance()
     */
    virtual bool has_full_rank() const
    {
        if (is_dirty(Rank))
        {
            full_rank_ =
               covariance().colPivHouseholderQr().rank() == covariance().rows();

            updated_internally(Rank);
        }

        return full_rank_;
    }
Esempio n. 7
0
    /**
     * \return Gaussian second centered moment in the square root form (
     * Cholesky decomposition)
     *
     * Computes the square root from other representation of not available
     *
     * \throws GaussianUninitializedException if the Gaussian is of dynamic-size
     *         and has not been initialized using SetStandard(dimension).
     * \throws InvalidGaussianRepresentationException if non-of the
     *         representation can be used as a source
     */
    virtual const SecondMoment& square_root() const
    {
        if (dimension() == 0)
        {
            fl_throw(GaussianUninitializedException());
        }

        if (is_dirty(SquareRootMatrix) && is_dirty(DiagonalSquareRootMatrix))
        {
            const SecondMoment& cov = covariance();

            switch (select_first_representation<4>({{DiagonalCovarianceMatrix,
                                                    DiagonalPrecisionMatrix,
                                                    CovarianceMatrix,
                                                    PrecisionMatrix}}))
            {
            case CovarianceMatrix:
            case PrecisionMatrix:
                fl::square_root(cov, square_root_);
                break;

            case DiagonalCovarianceMatrix:
            case DiagonalPrecisionMatrix:
                square_root_.setZero(dimension(), dimension());
                for (int i = 0; i < square_root_.rows(); ++i)
                {
                    square_root_(i, i) = std::sqrt(cov(i, i));
                }
                break;

            default:
                fl_throw(InvalidGaussianRepresentationException());
                break;
            }

            updated_internally(SquareRootMatrix);
        }

        return square_root_;
    }
Esempio n. 8
0
    /**
     * \return Gaussian second centered moment in the precision form (inverse
     * of the covariance)
     *
     * Computes the precision from other representation of not available
     *
     * \throws GaussianUninitializedException if the Gaussian is of dynamic-size
     *         and has not been initialized using SetStandard(dimension).
     * \throws InvalidGaussianRepresentationException if non-of the
     *         representation can be used as a source
     */
    virtual const SecondMoment& precision() const
    {
        if (dimension() == 0)
        {
            fl_throw(GaussianUninitializedException());
        }

        if (is_dirty(PrecisionMatrix) && is_dirty(DiagonalPrecisionMatrix))
        {
            const SecondMoment& cov = covariance();

            switch (select_first_representation<4>({{DiagonalCovarianceMatrix,
                                                    DiagonalSquareRootMatrix,
                                                    CovarianceMatrix,
                                                    SquareRootMatrix}}))
            {
            case CovarianceMatrix:
            case SquareRootMatrix:
                precision_ = covariance().inverse();
                break;

            case DiagonalCovarianceMatrix:
            case DiagonalSquareRootMatrix:
                precision_.setZero(dimension(), dimension());
                for (int i = 0; i < cov.rows(); ++i)
                {
                    precision_(i, i) = 1./cov(i, i);
                }
                break;

            default:
                fl_throw(InvalidGaussianRepresentationException());
                break;
            }

            updated_internally(PrecisionMatrix);
        }

        return precision_;
    }
Esempio n. 9
0
File: swapper.c Progetto: gz/aos10
/**
 * This function will select a page (based on second chance)
 * and swap it out to file system. However if the selected page
 * was not dirty then we just need to mark it swapped again and
 * can return immediatly.
 * We stop the initiator thread as long as we're swapping
 * data out to the file system. The thread is restarted in the
 * write callback function (above).
 *
 * @param initiator ID of the thread who caused the swapping to happen
 * @return	SWAPPING_PENDING in case we need to write the page to the disk
 * 			SWAPPING_COMPLETE in case the page was not dirty
 * 			OUT_OF_SWAP_SPACE if our swap space is already full
 * 			NO_PAGE_AVAILABLE if second_chance_select did not find a page
 */
int swap_out(L4_ThreadId_t initiator) {
	page_queue_item* page = second_chance_select(&active_pages_head);
	if(page == NULL) {
		return NO_PAGE_AVAILABLE;
	}
	assert(!is_referenced(page));

	// decide where in the swap file our page will be
	if(page->swap_offset < 0 && (page->swap_offset = allocate_swap_entry()) < 0)
		return OUT_OF_SWAP_SPACE;

	dprintf(1, "swap_out: Second chance selected page: thread:0x%X vaddr:0x%X swap_offset:0x%X\n", page->tid, page->virtual_address, page->swap_offset);

	if(is_dirty(page)) {
		dprintf(1, "Selected page is dirty, need to write to swap space\n");

		page->to_swap = PAGESIZE;
		page->initiator = initiator;
		TAILQ_INSERT_TAIL(&swapping_pages_head, page, entries);

		file_table_entry* swap_fd = get_process(root_thread_g)->filetable[SWAP_FD];
		assert(swap_fd != NULL);

		data_ptr physical_page = pager_physical_lookup(page->tid, page->virtual_address);
		assert(physical_page != NULL);

		// write page in swap file
		assert(PAGESIZE % BATCH_SIZE == 0);
		for(int write_offset=0; write_offset < page->to_swap; write_offset += BATCH_SIZE) {
			nfs_write(
				&swap_fd->file->nfs_handle,
				page->swap_offset + write_offset,
				BATCH_SIZE,
				physical_page + write_offset,
				&swap_write_callback,
				(int)page
			);
		}

		return SWAPPING_PENDING;
	}
	else {
		assert(page->swap_offset >= 0);
		page_table_entry* pte = pager_table_lookup(page->tid, page->virtual_address);
		frame_free(CLEAR_LOWER_BITS(pte->address));
		mark_swapped(pte, page->swap_offset);
		free(page);

		return SWAPPING_COMPLETE;
	}

}
Esempio n. 10
0
    /**
     * \return Log normalizing constant
     *
     * \throws see has_full_rank()
     */
    virtual Real log_normalizer() const
    {
        if (is_dirty(Normalizer))
        {
            if (has_full_rank())
            {
                log_norm_ =
                    -0.5
                    * (std::log(covariance_determinant())
                       + Real(dimension()) * std::log(2.0 * M_PI));
            }
            else
            {
                log_norm_ = 0.0; // FIXME
            }

            updated_internally(Normalizer);
        }

        return log_norm_;
    }
Esempio n. 11
0
void RedScreen::periodic_update()
{
    bool need_update;
    RecurciveLock lock(_update_lock);
    if (is_dirty()) {
        need_update = true;
    } else {
        if (!_forec_update_timer) {
            _owner.deactivate_interval_timer(*_update_timer);
            _periodic_update = false;
        }
        need_update = false;
    }
    lock.unlock();

    if (need_update) {
        if (update_by_interrupt()) {
            interrupt_update();
        } else {
            update();
        }
    }
}
Esempio n. 12
0
block_t cl_list_consolidate(const void * cfg,
		serial_t serialno,
		block_t list_block,
		uint8_t type,
		int item_size,
		int (*is_dirty)(void*),
		int (*is_free)(void*)){

	cl_block_data_t cl_block_data;
	cl_block_data_t new_cl_block_data;
	cl_list_block_t * list;
	cl_list_block_t * new_list;
	block_t new_block;
	block_t prev_block;
	block_t old_prev_block;
	block_t old_current_block;
	int i, j;
	block_t new_current_block;
	int total_items;

	int copied_items;

	new_block = cl_block_alloc(cfg, serialno, list_block, type);
	if ( new_block == BLOCK_INVALID ){
		cl_error("no more blocks\n");
		return BLOCK_INVALID;
	}

	list = (cl_list_block_t*)(cl_block_data.data);
	new_list = (cl_list_block_t*)(new_cl_block_data.data);
	total_items = calc_total_items(item_size);

	cl_debug(DEBUG_LEVEL, "consolidate list on new block %d\n", new_block);

	new_cl_block_data.hdr.serialno = serialno;
	new_cl_block_data.hdr.type = type;
	new_cl_block_data.hdr.status = 0xFF;
	memset(new_cl_block_data.data, 0xFF, BLOCK_DATA_SIZE);
	new_current_block = new_block;
	new_list->hdr.prev = BLOCK_INVALID;
	old_prev_block = BLOCK_INVALID;

	j = 0;
	copied_items = 0;
	for( list->hdr.next = list_block; list->hdr.next != BLOCK_INVALID ; ){
		old_current_block = list->hdr.next;
		if ( cl_block_load(cfg, list->hdr.next, &cl_block_data) < 0 ){
			return -1;
		}

		//make sure the loaded block is valid
		if ( (list->hdr.prev != old_prev_block) || //linking is not correct
				(list_typeisvalid(cl_block_data.hdr.type) == false) || //block type is not correct
				(serialno != cl_block_data.hdr.serialno) || //serialno is not correct
				(cl_block_data.hdr.status != BLOCK_STATUS_CLOSED) //block status must be closed
		){
			cl_debug(DEBUG_LEVEL, "--------------------END OF LIST %d != %d %d != %d 0x%X != 0x%X\n",
					list->hdr.prev, old_prev_block,
					serialno, cl_block_data.hdr.serialno,
					cl_block_data.hdr.status, BLOCK_STATUS_CLOSED);
			break; //end of the list
		}

		old_prev_block = old_current_block;


		for(i = 0; i < total_items; i++){
			if ( is_free( get_item(list, i, item_size) )){
				break;
			} else if ( !is_dirty( get_item(list, i, item_size) ) ){
				memcpy(get_item(new_list, j, item_size), get_item(list, i, item_size), item_size);
				j++;
				copied_items++;
				if ( j == total_items ){
					//save the current block to the disk
					new_list->hdr.next = cl_block_alloc(cfg, serialno, new_current_block, type | BLOCK_TYPE_LINKED_LIST_FLAG);
					cl_debug(DEBUG_LEVEL, "save block %d (prev:%d, next:%d)\n", new_current_block, new_list->hdr.prev, new_list->hdr.next);
					//hwpl_debug("save block %d (prev:%d, next:%d)\n", new_current_block, new_list->hdr.prev, new_list->hdr.next);
					if ( cl_block_save(cfg, new_current_block, &new_cl_block_data) < 0 ){
						cl_error("failed to save block %d\n", new_current_block);
						return -1;
					}
					prev_block = new_current_block;
					new_current_block = new_list->hdr.next;
					memset(new_cl_block_data.data, 0xFF, BLOCK_DATA_SIZE);
					new_list->hdr.prev = prev_block;
					j = 0;
				}
			}
		}
	}

	//save the last block
	new_list->hdr.next = BLOCK_INVALID;
	if ( cl_block_save(cfg, new_current_block, &new_cl_block_data) < 0 ){
		return -1;
	}
	return new_block;
}
Esempio n. 13
0
int
main(int argc, char *argv[])
#endif
{
	spcs_s_info_t ustats;
	struct timeval tout;
	fd_set readfds;
	char *errmessage, *ch;
	int c, period, prev;
	int count = 0, dflag = 0;
	int fd = fileno(stdin);

	errmessage = NULL;

	if (strcmp(argv[0], "sd_stats") != 0)
		errmessage = getenv("SD_STATS_USAGE");

	if (errmessage == NULL)
		errmessage = gettext("Usage: sd_stats [-Mz] "
				"[-d delay_time] [-l logfile] [-r range]");

	if (SDBC_IOCTL(SDBC_MAXFILES, &sdbc_max_devices,
	    0, 0, 0, 0, &ustats) == SPCS_S_ERROR) {
		if (ustats) {  	/* if SPCS_S_ERROR */
			spcs_s_report(ustats, stderr);
			spcs_s_ufree(&ustats);
		}
		(void) fprintf(stderr, gettext("cannot get maxfiles\n"));
		exit(1);
	}
	on_off = calloc(sdbc_max_devices, sizeof (int));
	dual_on_off = calloc(sdbc_max_devices, sizeof (int));
	updates_prev = calloc(sdbc_max_devices, sizeof (int));
	samples = calloc(sdbc_max_devices, sizeof (int));
	rate_prev = calloc(sdbc_max_devices, sizeof (double));
	cs_cur = malloc(sizeof (_sd_stats_t) +
	    (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
	cs_prev = malloc(sizeof (_sd_stats_t) +
	    (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
	cs_persec = malloc(sizeof (_sd_stats_t) +
	    (sdbc_max_devices - 1) * sizeof (_sd_shared_t));
	range = malloc(100);

	if (!on_off || !dual_on_off || !updates_prev || !samples ||
	    !rate_prev || !cs_cur || !cs_prev || !cs_persec || !range) {
		(void) fprintf(stderr, gettext("no free memory\n"));
		exit(1);
	}

	*range = '\0';

	while ((c = getopt(argc, argv, "DMzd:l:r:h")) != EOF) {

		prev = c;
		switch (c) {

		case 'd':
			delay = atoi(optarg);
			ch = optarg;
			while (*ch != '\0') {
				if (!isdigit(*ch))
					errflg++;
				ch++;
			}
			break;

		case 'l':
			logfd = open(optarg, O_CREAT|O_WRONLY|O_TRUNC, 0644);
			break;

		case 'r':
			ch = optarg;
			while (*ch != '\0') {
				if ((!isdigit(*ch)) && (*ch != ',') &&
				    (*ch != ':'))
					errflg++;
				ch++;
			}
			if (errflg)
				break;

			range = realloc((char *)range,
					(strlen(range) + strlen(optarg) + 1)
					* sizeof (char));

			if (had_r_option)
				(void) strcat(range, ",");
			(void) strcat(range, optarg);
			had_r_option = 1;
			break;

		case 'z':
			if (SDBC_IOCTL(SDBC_ZAP_STATS, 0, 0, 0, 0, 0,
					&ustats) == SPCS_S_ERROR) {
				if (ustats) {
					spcs_s_report(ustats, stderr);
					spcs_s_ufree(&ustats);
				}
			}

			break;

		case 'D':
			dflag = 1;
			break;

		case 'M':
			mirror_sw = 1;
			break;

		case 'h':
		case '?':
		default :
			errflg++;
			break;
		}
	}

	if (errflg) {
		(void) fprintf(stderr, "%s\n", errmessage);
		exit(1);
	} else if (!prev) {
		if (argc > 1) {
			(void) fprintf(stderr, "%s\n", errmessage);
			exit(1);
		}
	}

	if (dflag) {
		exit(is_dirty());
	}


	/*
	 * A few curses routines to setup screen and tty interface
	 */
	(void) initscr();
	(void) cbreak();
	(void) noecho();
	(void) nonl();
	(void) erase();
	(void) clear();
	(void) refresh();

	setup_ranges(range);

	/*
	 * Set signal handle
	 */
	(void) sigset(SIGPIPE, leave);
	(void) sigset(SIGINT, leave);
	(void) sigset(SIGQUIT, leave);
	(void) signal(SIGFPE, leave);
	(void) signal(SIGSEGV, leave);

	USEC_INIT();
	currtime = USEC_READ();

	/*
	 * Wait one second before reading the new values
	 */
	(void) sleep(1);

	/*CONSTCOND*/
	while (1) {

		lasttime = currtime;
		currtime = USEC_READ();

		/*
		 * If less that 1 second, force it to one second
		 */
		if ((period = (currtime - lasttime) / 1000000) <= 0)
			period = 1;

		/*
		 * Calculate new per/period values for statistics
		 */
		Elapsed_Time += period;

		/*
		 * Display new statistics
		 */
		prheading(++count);

		if (mirror_sw) {
			if (dual_stats() < 0)
				mirror_sw = 0;
		} else if (toggle_total_sw)
			total_display();
		else
			display_cache();

		(void) move(0, 0);
		(void) refresh();
		if (logfd > -1) wrefresh_file(stdscr, logfd);

		FD_ZERO(&readfds);
		FD_SET(fd, &readfds);
		tout.tv_sec = delay;
		for (;;) {
			tout.tv_usec = 0;
			if (select(fd + 1, &readfds, (fd_set *)0, (fd_set *)0,
				&tout) <= 0)
				break;
			if ((c = getch()) == EOF) {
				(void) sleep(delay);
				break;
			}
			checkbuf(c);
			tout.tv_sec = 0;
		}
		(void) erase();
	}
#pragma error_messages(off, E_STATEMENT_NOT_REACHED)
	return (0);
#pragma error_messages(default, E_STATEMENT_NOT_REACHED)
}
Esempio n. 14
0
void opt_sim(struct memory_reference *instructions, uint32_t count, uint32_t *pt, int pages, int frames)
{
	struct opt_node * references;
	references = malloc((1 << 20) * sizeof(struct opt_node));
	memset(references, 0, (1 << 20) * sizeof(struct opt_node));
	char line_buffer[30];
	unsigned int instruction;
	instruction = 0;
	uint32_t page_number;
	struct opt_page valid_pages[frames];
	uint32_t i, k;
	int j, index;
	int next_frame;
    int max;

	for(i = 0; i < frames; i++){
		valid_pages[i].page_number = NOTHING_TO_SEE_HERE;
	}
    
    struct memory_reference current = instructions;

    for(i = 0; i < count; i++){
        index = -1;
        page_number = instructions[i].address >> 12;
        // search for page in frame table.  if it's not there, we need to add it.
        for(j = 0; j < next_frame; j++){
        	if(page_number == valid_pages[j].page_number){
        		index = j;
        	}
        }
        if(index < 0){
        	// we did not find the page in our frames, add it
        	if(next_frame == frames){
        		max = 0;
        		// if we are full, we need to swap
        		for(j = 0; j < next_frame; j++){
                    if(valid_pages[j].next_reference > valid_pages[max].next_reference){
                    	max = j;
                    } else if(valid_pages[j].next_reference == valid_pages[max].next_reference){
                    	if(!is_dirty(pt[valid_pages[max].page_number])){
                    		max = j;
                    	}
                    }
        		} // now we have the page to evict
        		if(is_dirty(pt[valid_pages[max].page_num])){
        			printf("page fault - evict dirty\n");
        			// increase disk write counter
        		} else {
        			printf("page fault - evict clean\n");
        		}
        		valid_pages[max].page_number = page_number;
        		valid_pages[max].next_reference = find_next_reference(instructions, count, i);
        		// update page table
        		
        	} else {
        		valid_pages[next_frame].page_number = page_number; // no eviction
                valid_pages[next_frame].next_reference = find_next_reference(instructions, count, i);
        		printf("page fault - no eviction\n");
        		next_frame++;
        	}
        } else {
        	printf("hit\n");
        }   
    }

    // keep a list of instruction numbers for each page
    // 
}
Esempio n. 15
0
 virtual bool      needs_update()       { return ((_w>0)&&(_h>0)&&is_dirty()&&(_list.num()>0)); }